이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
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];
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]++;
}
}
for (int i=0; i<m; i++)
{
int mn=INT_MAX;
if (a[i]<=b[i]) for (int j=a[i]; j<=b[i]; j++) mn=min(mn, cur[j]);
else
{
for (int j=a[i]; j<=n; j++) mn=min(mn, cur[j]);
for (int j=1; j<=b[i]; j++) mn=min(mn, cur[j]);
}
if (mn>=2)
{
res[i]=1;
if (a[i]<=b[i]) for (int j=a[i]; j<=b[i]; j++) cur[j]--, dp[j]++;
else
{
for (int j=a[i]; j<=n; j++) cur[j]--, dp[j]++;
for (int j=1; j<=b[i]; 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];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |