#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
mt19937 rng(time(0));
int n, m, a[nx], b[nx], cur[nx], dp[nx], res[nx];
vector<pair<int, int>> v;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=0; i<m; i++)
{
cin>>a[i]>>b[i];
v.push_back({rng(), i});
if (a[i]<=b[i]) for (int j=a[i]; j<=b[i]; j++) cur[j]++;
else
{
for (int j=a[i]; j<=n; j++) cur[j]++;
for (int j=1; j<=b[i]; j++) cur[j]++;
}
}
sort(v.begin(), v.end());
for (int i=0; i<m; i++)
{
int idx=v[i].second;
int mn=INT_MAX;
if (a[idx]<=b[idx]) for (int j=a[idx]; j<=b[idx]; j++) mn=min(mn, cur[j]);
else
{
for (int j=a[idx]; j<=n; j++) mn=min(mn, cur[j]);
for (int j=1; j<=b[idx]; j++) mn=min(mn, cur[j]);
}
if (mn>=2)
{
res[idx]=1;
if (a[idx]<=b[idx]) for (int j=a[idx]; j<=b[idx]; j++) cur[j]--, dp[j]++;
else
{
for (int j=a[idx]; j<=n; j++) cur[j]--, dp[j]++;
for (int j=1; j<=b[idx]; j++) cur[j]--, dp[j]++;
}
}
}
for (int i=1; i<=n; i++) if (dp[i]==0) return cout<<"impossible", 0;
for (int i=0; i<m; i++) cout<<res[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3044 ms |
2512 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |