Submission #186612

#TimeUsernameProblemLanguageResultExecution timeMemory
186612Ruxandra985Alternating Current (BOI18_alternating)C++14
0 / 100
3022 ms1976 KiB
#include <bits/stdc++.h> #define DIMN 100010 using namespace std; pair <int,int> v[DIMN]; int d[DIMN] , cer[DIMN] , f[DIMN] , sol[DIMN]; int main() { FILE *fin = stdin; FILE *fout = stdout; int n , m , i , j , ok , poz , what; fscanf (fin,"%d%d",&n,&m); for (i=1;i<=m;i++){ fscanf (fin,"%d%d",&v[i].first,&v[i].second); if (v[i].first <= v[i].second){ for (j = v[i].first ; j <= v[i].second ; j++){ d[j]++; } } else { for (j = v[i].first ; j <= n ; j++){ d[j]++; } for (j = 1 ; j <= v[i].second ; j++){ d[j]++; } } } for (j=1;j<=m;j++){ ok = 0; for (i=1;i<=n;i++){ if (d[i] == 1 && cer[i] < 3 && cer[i] > 0) ok = i; } if (ok){ for (i=1;i<=m;i++){ if (!f[i]){ /// inca e relevant if (v[i].first <= v[i].second && v[i].first <= ok && ok <= v[i].second){ poz = i; f[i] = 1; } else if (v[i].first > v[i].second && (ok >= v[i].first || ok <= v[i].second)){ poz = i; f[i] = 1; } } } what = cer[ok]; } else { what = 1; for (i=1;i<=m;i++){ if (!f[i]){ poz = i; f[i] = 1; break; } } } sol[poz] = what - 1; /// update for (i=1;i<=n;i++){ if ((v[poz].first <= v[poz].second && v[poz].first <= i && i <= v[poz].second) || (v[poz].first > v[poz].second && (i >= v[poz].first || i <= v[poz].second))){ /// i e afectat de interval d[i]--; if (cer[i] == 0){ if (what == 1) cer[i] = 2; else cer[i] = 1; } else if (cer[i] == 3){} else { /// e 1 sau 2 , cere ceva si i se da if (cer[i] == what){ cer[i] = 3; } } } } } for (i=1;i<=n;i++){ if (cer[i] > 0 && cer[i] < 3){ fprintf (fout,"impossible"); return 0; } } for (i=1;i<=m;i++){ fprintf (fout,"%d",sol[i]); } return 0; }

Compilation message (stderr)

alternating.cpp: In function 'int main()':
alternating.cpp:11:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf (fin,"%d%d",&n,&m);
     ~~~~~~~^~~~~~~~~~~~~~~~~~
alternating.cpp:13:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf (fin,"%d%d",&v[i].first,&v[i].second);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alternating.cpp:64:18: warning: 'poz' may be used uninitialized in this function [-Wmaybe-uninitialized]
         sol[poz] = what - 1;
         ~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...