QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619482 | #4632. Card Shark | ship2077 | WA | 21ms | 12504kb | C++23 | 1.0kb | 2024-10-07 14:21:56 | 2024-10-07 14:21:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=2e5+5;
vector<pair<int,int>>adj[M];
int n,m,x;vector<int>ans;string str;
void dfs(int x){
while (!adj[x].empty()){
auto [z,y]=adj[x].back();adj[x].pop_back();
dfs(y);ans.emplace_back(z);
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m>>x;
for (int i=1;i<=n;i++){
string str;cin>>str;
int len=str.length(),pos;str=" "+str;
for (int j=1;j<=len;j++)
if (str[j]=='1') {pos=j;break;}
if (pos>m) return puts("-1"),0;
for (int j=1;j<=len;j++)
if ((str[j]-'0')^((j-pos)%m==0))
return puts("-1"),0;
int rpos=(len-pos)/m*m+pos;
adj[pos].emplace_back(i,m-(len-rpos));
}
for (int i=1;i<=n;i++) reverse(adj[i].begin(),adj[i].end());
dfs(x);
if (ans.size()!=n) return puts("-1"),0;
reverse(ans.begin(),ans.end());
for (auto x:ans) printf("%d ",x);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4136kb
input:
5 4 3 0100010 00100 001000100 0010 0100010
output:
2 1 3 5 4
result:
ok single line: '2 1 3 5 4 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
4 2 1 010 10101 010 10101
output:
2 1 4 3
result:
ok single line: '2 1 4 3 '
Test #3:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
1 5 3 001000010000100
output:
1
result:
ok single line: '1 '
Test #4:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
2 5 3 01000 00010
output:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
1 5 3 11111
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
10 5 3 000010000100 0001000010000100001 000100 00010 00010000100 0010 00001000010000100001000010 00010 001 001000010
output:
6 2 1 9 7 3 10 4 8 5
result:
ok single line: '6 2 1 9 7 3 10 4 8 5 '
Test #7:
score: 0
Accepted
time: 1ms
memory: 4164kb
input:
1000 5 4 010000100 00100 001000 00010000100001000 0010000100 100 00001000010000 000010 00010000100001000010 01000010000100 100 0000100 1 00010000 0010 0001 10000100 00001000 1 000100 0000100001 000010000100001000 00100001 010 00100001000010000100 0000100001 010 00100001000010000100001 0000100001 001...
output:
4 1 2 3 10 5 15 9 14 6 23 7 11 25 28 8 16 12 30 31 13 18 24 20 39 27 34 36 37 21 22 35 47 52 26 29 40 43 44 53 38 17 56 19 42 58 59 60 32 33 57 48 45 65 50 54 71 63 74 41 64 51 73 79 75 80 81 90 62 68 46 70 67 99 87 100 69 108 72 97 76 77 82 83 86 88 49 93 94 98 103 55 101 61 102 106 104 109 105 112...
result:
ok single line: '4 1 2 3 10 5 15 9 14 6 23 7 11...88 984 989 992 994 991 999 998 '
Test #8:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
1000 5 2 0001000010000100001 00100001 000010 0010000 000100001000 100001000010000100001000010000 010000100001 00010 1000010000100001000 010 010000100001000010 001000 1000010000 000010000100001000 10000 10000100 01000 100001000010 00100 00100 000010000 1000010000100001000010000100001 100 100001000010...
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 21ms
memory: 12504kb
input:
100000 5 2 1000010000 1000010 0010000100001 00100 01000010000100001 00010000 10000100 010000 001 010 1000010000 000010000 0000100001000 00100001000 010 1000 10000100 0100 1000 00001000010 01000010000 1 01 001000010000 0000100001 00100001000010 00010000100001 010 0010000100001000010 0010000100 00001 ...
output:
5 12 1 2 6 7 3 13 8 11 16 10 27 20 38 25 31 32 4 9 33 15 50 14 18 24 17 26 56 61 21 19 23 34 22 39 29 69 28 79 30 35 108 37 51 55 57 70 41 111 36 72 47 113 73 42 76 78 40 120 46 48 43 49 52 124 80 81 44 128 83 62 53 64 45 135 66 58 85 137 59 54 60 74 77 140 63 86 67 84 96 98 65 88 99 68 101 90 71 10...
result:
ok single line: '5 12 1 2 6 7 3 13 8 11 16 10 2... 99986 99995 99999 99989 99994 '
Test #10:
score: 0
Accepted
time: 1ms
memory: 4032kb
input:
5 10 4 000010000000001000000 0100000 00000100000000 0001000000000100000000010000000001 000000000100000000010000
output:
4 5 3 2 1
result:
ok single line: '4 5 3 2 1 '
Test #11:
score: 0
Accepted
time: 1ms
memory: 3856kb
input:
5 1000 581 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
4 5 2 1 3
result:
ok single line: '4 5 2 1 3 '
Test #12:
score: 0
Accepted
time: 1ms
memory: 3896kb
input:
5 1000 406 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
-1
result:
ok single line: '-1'
Test #13:
score: 0
Accepted
time: 4ms
memory: 4608kb
input:
5 100000 91799 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
3 4 1 5 2
result:
ok single line: '3 4 1 5 2 '
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 3836kb
input:
10 20 17 000000000010000000000000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000000000000010000000000000000000100000000000000000001000000000000 0000000000001000 00000000000000001000000000000000000 000000000001000 100000000 0100000000000000000001000000...
output:
9 5 7 4 3 6 8 1 10 2
result:
wrong answer 1st lines differ - expected: '3 6 8 1 10 2 9 5 7 4', found: '9 5 7 4 3 6 8 1 10 2 '