#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=1e5+100;
vector <pii> g[N];
ll ans[N];
int32_t main(){
ll n,m;
cin >> n >> m;
for (int i=0;i<m;i++){
ll a,b;
cin >> a >> b;
g[a].pb({b,i});
}
for (int i=1;i<=n;i++){
sort(g[i].begin(),g[i].end());
reverse(g[i].begin(),g[i].end());
}
ll cnt1=0,cnt=0;
for (int i=1;i<=n;i++){
for (int j=0;j<g[i].size();j++){
ll k=g[i][j].F;
if (cnt<cnt1){
if (cnt>=i-1){
cnt=max(cnt,k);
ans[g[i][j].S]=0;
}
continue;
}
else{
if (cnt1>=i-1){
cnt1=max(cnt1,k);
ans[g[i][j].S]=1;
}
}
}
}
if (cnt==n && cnt1==n){
for (int i=0;i<m;i++){
cout << ans[i];
}
return 0;
}
cout << "impossible" << endl;
}
Compilation message
alternating.cpp: In function 'int32_t main()':
alternating.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<g[i].size();j++){
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Incorrect |
4 ms |
2680 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Incorrect |
4 ms |
2680 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Incorrect |
4 ms |
2680 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
6396 KB |
Output is correct |
2 |
Correct |
5 ms |
2680 KB |
Output is correct |
3 |
Correct |
59 ms |
4856 KB |
Output is correct |
4 |
Correct |
62 ms |
5288 KB |
Output is correct |
5 |
Correct |
137 ms |
7288 KB |
Output is correct |
6 |
Correct |
132 ms |
7288 KB |
Output is correct |
7 |
Correct |
128 ms |
7320 KB |
Output is correct |
8 |
Correct |
8 ms |
2812 KB |
Output is correct |
9 |
Correct |
5 ms |
2680 KB |
Output is correct |
10 |
Correct |
142 ms |
7544 KB |
Output is correct |
11 |
Correct |
113 ms |
6324 KB |
Output is correct |
12 |
Correct |
138 ms |
7260 KB |
Output is correct |
13 |
Correct |
5 ms |
2680 KB |
Output is correct |
14 |
Correct |
5 ms |
2808 KB |
Output is correct |
15 |
Correct |
144 ms |
7432 KB |
Output is correct |
16 |
Correct |
61 ms |
5240 KB |
Output is correct |
17 |
Correct |
148 ms |
7496 KB |
Output is correct |
18 |
Correct |
127 ms |
7184 KB |
Output is correct |
19 |
Correct |
10 ms |
2936 KB |
Output is correct |
20 |
Correct |
118 ms |
7160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
4 ms |
2552 KB |
Output is correct |
3 |
Incorrect |
4 ms |
2680 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |