QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#385460 | #4632. Card Shark | james1BadCreeper# | WA | 11ms | 27124kb | C++14 | 1.4kb | 2024-04-10 19:30:25 | 2024-04-10 19:30:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, b;
int cur[N];
char s[N];
vector<pair<int, int>> G[N];
vector<int> path;
void dfs(int x) {
for (int &i = cur[x]; i < G[x].size(); )
path.push_back(G[x][i].second), dfs(G[x][i++].first);
}
int main(void) {
ios::sync_with_stdio(0);
cin >> n >> m >> b;
for (int i = 1; i <= n; ++i) {
cin >> s; int l = strlen(s), res = -1;
for (int j = 0; j < l; ++j)
if (s[j] == '1') {
if (res == -1) res = j % m;
else if (res != j % m) return cout << "-1\n", 0;
}
for (int j = 0; j < l; ++j) {
if (j % m == res && s[j] != '1') return cout << "-1\n", 0;
if (j % m != res && s[j] == '1') return cout << "-1\n", 0;
}
int c1 = 0, c2 = 0;
for (int j = 0; j < l; ++j)
if (s[j] == '1') break;
else ++c1;
for (int j = l - 1; j >= 0; --j)
if (s[j] == '1') break;
else ++c2;
G[c1].emplace_back(m - 1 - c2, i);
}
dfs(b - 1);
if (path.size() == n) {
for (int i : path) cout << i << " ";
cout << "\n";
return 0;
}
cout << "-1\n";
return 0;
}
/*
10 5 3
000010000100
0001000010000100001
000100
00010
0010
00001000010000100001000010
00010000100
00010
001
001000010
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 27088kb
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: 27092kb
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: 0ms
memory: 27124kb
input:
1 5 3 001000010000100
output:
1
result:
ok single line: '1 '
Test #4:
score: 0
Accepted
time: 3ms
memory: 27112kb
input:
2 5 3 01000 00010
output:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 7ms
memory: 27036kb
input:
1 5 3 11111
output:
-1
result:
ok single line: '-1'
Test #6:
score: -100
Wrong Answer
time: 11ms
memory: 27040kb
input:
10 5 3 000010000100 0001000010000100001 000100 00010 00010000100 0010 00001000010000100001000010 00010 001 001000010
output:
6 2 1 9 7 3 10 4 5 8
result:
wrong answer 1st lines differ - expected: '6 2 1 9 7 3 10 4 8 5', found: '6 2 1 9 7 3 10 4 5 8 '