Submission #1113942

#TimeUsernameProblemLanguageResultExecution timeMemory
1113942mariaclaraAlternating Current (BOI18_alternating)C++17
0 / 100
3058 ms2888 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 1e5+5; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mk make_pair #define pb push_back #define fr first #define sc second int n, m, group[MAXN]; int main() { cin >> n >> m; vector<pair<pii,int>> v(m); for(int i = 0; i < m; i++) { cin >> v[i].fr.fr >> v[i].fr.sc; if(v[i].fr.fr > v[i].fr.sc) v[i].fr.sc += n; v[i].sc = i; } sort(all(v)); auto [A,B] = v[0].fr; bool possible = 0; for(int i = 1; i < sz(v); i++) { // i é o primeiro elemento do 2° grupo group[v[i].sc] = 1; auto [C,D] = v[i].fr; int B_ = B; for(int j = i+1; j < sz(v); j++) { if(B_ <= D and B_ - A < n - 1) { if(v[j].fr.fr <= B_+1) B_ = max(B_, v[j].fr.sc); group[v[j].sc] = 0; } else { if(v[j].fr.fr <= D+1) D = max(D, v[j].fr.sc); group[v[j].sc] = 1; } } if(B_ - A >= n-1 and D - C >= n-1) { possible = 1; break; } group[v[i].sc] = 0; if(v[i].fr.fr <= B+1) B = max(B, v[i].fr.sc); } if(!possible) { cout << "impossible\n"; return 0; } for(int i = 0; i < m; i++) cout << group[i]; }
#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...