Submission #863400

#TimeUsernameProblemLanguageResultExecution timeMemory
863400Trisanu_DasAlternating Current (BOI18_alternating)C++17
55 / 100
3047 ms4772 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 100020; int n, m; int dis(int x, int y){ if(y < x) return n + y - x + 1; return y - x + 1; } vector<pair<int, int> > A[100020]; int answer[100020], S[100020][2]; int main() { cin >> n >> m; int ci, cm; ci = cm = 0; for(int i = 1; i <= m; i++){ int x, y; cin >> x >> y; A[x - 1].push_back(make_pair(dis(x, y), i)); if(dis(x, y) > cm) ci = x - 1, cm = dis(x, y); } for(ci = 0; ci < n; ++ci){ for(int p = 0; p < n; ++p) { int i = (p + ci) % n; for(int j = 0; j < A[i].size(); ++j){ int x = A[i][j].first; int c = 0; for(int k = 0; k < n; ++k){ int now = (i + k) % n; if(S[now][0] == 0){ c = 0; break; } if(S[now][1] == 0) { c = 1; break; } } answer[A[i][j].second] = c; for(int k = 0; k < x; ++k) S[(i + k) % n][c] = 1; } } bool B = true; for(int i = 0; i < n; ++ i) if(S[i][0] == 0 || S[i][1] == 0){ B = false; break; } if(B) break; for(int i = 0; i < n; ++i) S[i][0] = S[i][1] = 0; } for(int i = 0; i < n; ++ i) if(S[i][0] == 0 || S[i][1] == 0) return printf("impossible"), 0; for(int i = 1; i <= m; ++ i) printf("%d", answer[i]); }

Compilation message (stderr)

alternating.cpp: In function 'int main()':
alternating.cpp:28:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |       for(int j = 0; j < A[i].size(); ++j){
      |                      ~~^~~~~~~~~~~~~
#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...