QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99510 | #42. Alternating Current | ShanLunjiaJian | 0 | 15ms | 3020kb | C++14 | 3.1kb | 2023-04-22 19:40:34 | 2023-04-22 19:40:36 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
using std::sort;
int n,m,ans[100002];
struct P{ int l,r,id; }a[100002];
inline bool in(int p,P a){ return a.l<a.r?a.l<=p&&p<a.r:a.r<=p&&p<=a.l+n; }
inline int len(P a){ return a.l<a.r?a.r-a.l:a.r+n-a.l; }
inline int min(int x,int y){ return x<y?x:y; }
inline int max(int x,int y){ return x>y?x:y; }
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d%d",&a[i].l,&a[i].r),a[i].l--,a[i].r--,((++a[i].r)%=n),a[i].id=i;//,printf("debug: %d %d\n",a[i].l,a[i].r);
int p=1;
for(int i=1;i<=m;i++) if(/*printf("debug: %d\n",len(a[i])),*/len(a[i])>len(a[p])) p=i;
int s=a[p].l;
//printf("s: %d, [%d,%d)\n",s,a[p].l,a[p].r);
for(int i=1;i<=m;i++) a[i].l=(a[i].l-s+n)%n,a[i].r=(a[i].r-s+n)%n,(a[i].l>=a[i].r)&&(a[i].r+=n);//,printf("%d %d %d\n",a[i].l,a[i].r,a[i].id);
sort(a+1,a+m+1,[](P a,P b){ return a.l==b.l?a.r>b.r:a.l<b.l; });
int q=0;
for(int i=2;i<=m;i++) if(a[i].r>=n&&(!q||a[i].l<a[q].l)) q=i;
if(!q) return printf("impossible"),0;
//case p!=q
bool flag=0;
int x=a[1].r,y=a[q].r-n,type=0;//type of x
ans[a[1].id]=0,ans[a[q].id]=1;
//printf("[%d,%d) [%d,%d)\n",a[1].l,a[1].r,a[q].l,a[q].r);
for(int i=2;i<=m;i++)
{
//printf("now: [%d,%d) id %d, 0: %d, 1: %d\n",a[i].l,a[i].r,a[i].id,type?y:x,type?x:y);
if(a[i].l<=min(x,y))
{
if(i!=q)
if(a[i].r>x) y=x,x=a[i].r,ans[a[i].id]=(type^=1);//,printf("choose %d\n",type);
else if(a[i].r>y) y=a[i].r,ans[a[i].id]=(type^1);//,printf("choose %d\n",type^1);
else ans[a[i].id]=0;
else type?(x=a[q].r):(y=a[q].r);
if(x>=n&&y>=n){ flag=1;break; }
}
else break;
}
//printf("last: 0: %d, 1: %d\n",type?y:x,type?x:y);
if(flag)
{
for(int i=1;i<=m;i++) printf("%d",ans[i]);
printf("\n");
return 0;
}
//printf("?");
int r=0;
for(int i=2;i<=m;i++) if(i!=q&&a[i].r>=n&&a[q].l<=a[i].l&&a[i].r-n<=a[1].r) r=i;
if(!r) return printf("impossible"),0;
x=a[1].r,y=a[r].r-n,type=0;
ans[a[1].id]=ans[a[q].id]=0,ans[a[r].id]=1;
for(int i=2;i<=m;i++)
{
//printf("now: [%d,%d) id %d, 0: %d, 1: %d\n",a[i].l,a[i].r,a[i].id,type?y:x,type?x:y);
if(a[i].l<=min(x,y))
{
if(i!=q&&i!=r)
if(a[i].r>x) y=x,x=a[i].r,ans[a[i].id]=(type^=1);//,printf("choose %d\n",type);
else if(a[i].r>y) y=a[i].r,ans[a[i].id]=(type^1);//,printf("choose %d\n",type^1);
else ans[a[i].id]=0;
else if(i==q) type?(y=a[q].r):(x=a[q].r);
else if(i==r) type?(x=a[r].r):(y=a[r].r);
if(x>=n&&y>=n){ flag=1;break; }
}
else break;
}
if(flag)
{
for(int i=1;i<=m;i++) printf("%d",ans[i]);
printf("\n");
}
else printf("impossible");
/*static bool f[100002][2];
for(int i=1;i<=m;i++)
for(int j=a[i].l;j<a[i].r;j++) f[j%n][ans[a[i].id]]=1;
for(int i=0;i<n;i++) if(!(f[i][0]&&f[i][1])) printf("? %d %d %d\n",i,f[i][0],f[i][1]);*/
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 13
Accepted
time: 0ms
memory: 1556kb
input:
15 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15 1 15
output:
010000000000000
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 1548kb
input:
15 2 1 15 1 15
output:
01
result:
ok
Test #3:
score: -13
Wrong Answer
time: 0ms
memory: 1744kb
input:
15 5 13 6 12 13 7 12 14 10 1 11
output:
impossible
result:
wrong answer 'impossible' claimed, but there is a solution
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #99:
score: 19
Accepted
time: 15ms
memory: 2728kb
input:
100000 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 10000...
output:
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok
Test #100:
score: 0
Accepted
time: 1ms
memory: 1752kb
input:
100000 2 1 100000 1 100000
output:
01
result:
ok
Test #101:
score: 0
Accepted
time: 5ms
memory: 2108kb
input:
100000 50000 1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 9996...
output:
impossible
result:
ok
Test #102:
score: 0
Accepted
time: 15ms
memory: 2332kb
input:
100000 50002 1 100000 2 99999 3 99998 4 99997 5 99996 6 99995 7 99994 8 99993 9 99992 10 99991 11 99990 12 99989 13 99988 14 99987 15 99986 16 99985 17 99984 18 99983 19 99982 20 99981 21 99980 22 99979 23 99978 24 99977 25 99976 26 99975 27 99974 28 99973 29 99972 30 99971 31 99970 32 99969 33 9996...
output:
010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok
Test #103:
score: -19
Wrong Answer
time: 15ms
memory: 3020kb
input:
100000 95300 17946 17948 33214 33215 731 735 90652 90652 58810 58810 87592 87593 29477 29477 46179 46180 84232 84233 23054 23054 19780 19781 86542 86544 1833 1833 57179 57181 89599 89601 41733 41733 55557 55557 99336 99337 33965 33967 61232 61235 93747 93748 82461 82462 57207 57207 80116 80119 50062...
output:
impossible
result:
wrong answer 'impossible' claimed, but there is a solution
Subtask #5:
score: 0
Skipped
Dependency #1:
0%