QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#26042 | #2833. Hamilton | Hakujitsu | WA | 11ms | 3724kb | C++ | 2.7kb | 2022-04-05 22:58:23 | 2022-04-29 02:47:44 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{
cerr << " " << H;
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int n;
void solve(){
vector<string> mp(n);
for (auto &s : mp) cin >> s;
vector<int> res;
for (int i = 0; i < n; i += 1) {
if(res.size() < 2) {
res.emplace_back(i);
continue;
}
auto cal = [&](vector<int> &res) {
int diff = 0;
for (int j = 1; j < res.size(); j += 1) {
auto c1 = mp[res[j]][res[j - 1]];
auto c2 = mp[res[j]][res[(j + 1) % res.size()]];
diff += c1 != c2;
}
return diff;
};
if(res.size() <= 20) {
for (int j = 0; i <= res.size(); j += 1) {
auto t = res;
t.insert(t.begin() + j, i);
if(cal(t) <= 1) {
res = t;
break;
}
}
continue;
}
auto get = [&](int x) {
x = (x + int(res.size())) % res.size();
return res[x];
};
int diff = cal(res);
auto check = [&](int pos) {
pos = (pos + int(res.size())) % res.size();
int cur = diff;
auto c1 = mp[get(pos)][get(pos + 1)];
auto c2 = mp[get(pos - 1)][get(pos)];
if(pos != 0) cur -= c1 != c2;
c2 = mp[get(pos + 1)][get(pos + 2)];
if(pos + 1 != res.size()) cur -= c1 != c2;
c1 = mp[i][get(pos)];
c2 = mp[get(pos - 1)][get(pos)];
if(pos != 0) cur += c1 != c2;
c1 = mp[i][get(pos + 1)];
c2 = mp[get(pos + 1)][get(pos + 2)];
if(pos + 1 != res.size()) cur += c1 != c2;
c1 = mp[i][get(pos)];
c2 = mp[i][get(pos + 1)];
cur += c1 != c2;
return cur <= 1;
};
for (int j = -1; j < int(res.size()); j += 1) {
if(check(j)) {
//debug(i, j);
res.insert(res.begin() + j + 1, i);
break;
}
}
}
for (int i = 0; i < n; i += 1) {
cout << res[i] + 1 << " \n"[i + 1 == n];
}
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
while(cin >> n) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
input:
3 001 000 100 4 0000 0000 0000 0000
output:
3 1 2 4 3 1 2
result:
ok 2 cases.
Test #2:
score: 0
Accepted
time: 3ms
memory: 3556kb
input:
3 000 000 000 3 010 100 000 3 011 100 100 3 011 101 110
output:
3 1 2 1 3 2 3 1 2 3 1 2
result:
ok 4 cases.
Test #3:
score: 0
Accepted
time: 2ms
memory: 3564kb
input:
4 0000 0000 0000 0000 4 0000 0001 0000 0100 4 0100 1010 0100 0000 4 0111 1000 1000 1000 4 0010 0011 1101 0110 4 0111 1011 1100 1100 4 0111 1011 1101 1110 4 0000 0011 0101 0110 4 0101 1010 0100 1000 4 0011 0011 1100 1100 4 0010 0001 1000 0100
output:
4 3 1 2 4 3 1 2 3 4 1 2 3 1 4 2 4 1 3 2 4 3 1 2 4 3 1 2 3 1 4 2 3 4 1 2 4 1 3 2 3 4 1 2
result:
ok 11 cases.
Test #4:
score: 0
Accepted
time: 1ms
memory: 3724kb
input:
5 00000 00000 00000 00000 00000 5 00001 00000 00000 00000 10000 5 00010 00010 00000 11000 00000 5 00000 00001 00001 00001 01110 5 00001 00001 00001 00001 11110 5 00101 00100 11011 00100 10100 5 01111 10011 10000 11000 11000 5 00011 00011 00011 11101 11110 5 01101 10111 11001 01001 11110 5 00111 0011...
output:
5 4 3 1 2 5 4 3 1 2 5 4 3 1 2 4 5 3 1 2 4 5 3 1 2 5 1 3 4 2 5 4 3 1 2 3 5 4 1 2 4 5 3 1 2 5 4 1 3 2 5 4 3 1 2 4 3 5 1 2 4 5 3 1 2 5 4 3 1 2 5 4 3 1 2 4 3 5 1 2 4 3 1 5 2 3 4 5 1 2 5 3 4 1 2 5 4 1 3 2 4 5 3 1 2 3 5 1 4 2 5 4 1 3 2 4 3 5 1 2 4 5 1 3 2 4 3 5 1 2 4 3 5 1 2 5 3 4 1 2 3 1 4 5 2 3 5 4 1 2 ...
result:
ok 34 cases.
Test #5:
score: 0
Accepted
time: 2ms
memory: 3572kb
input:
6 000000 000000 000000 000000 000000 000000 6 000000 000000 000001 000000 000000 001000 6 010000 100100 000000 010000 000000 000000 6 000100 000000 000100 101010 000100 000000 6 000100 000000 000100 101011 000100 000100 6 001000 001000 110111 001000 001000 001000 6 001100 000100 100100 111011 000100...
output:
6 5 4 3 1 2 6 5 4 3 1 2 6 5 4 1 3 2 5 4 6 3 1 2 5 4 6 3 1 2 1 3 6 5 4 2 3 4 6 5 1 2 5 3 6 4 1 2 4 3 5 1 6 2 1 5 6 3 4 2 4 6 5 1 3 2 3 1 6 5 4 2 5 6 4 3 1 2 6 5 4 3 1 2 6 5 4 3 1 2 6 5 4 3 1 2 3 6 1 5 4 2 5 4 6 3 1 2 6 5 4 1 3 2 6 5 4 3 1 2 4 6 5 3 1 2 3 4 6 5 1 2 5 4 6 3 1 2 6 5 3 4 1 2 5 4 6 3 1 2 ...
result:
ok 156 cases.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
7 0000010 0001011 0001010 0110100 0001001 1110001 0100110 7 0101001 1011000 0101100 1110010 0010010 0001100 1000000 7 0001111 0011001 0100100 1100101 1011000 1000000 1101000 7 0111111 1011101 1101001 1110010 1100010 1001101 1110010 7 0010111 0010001 1101010 0010000 1000011 1010100 1100100 7 0001010 ...
output:
3 7 4 6 5 1 2 6 5 3 4 1 7 2 7 5 6 4 3 1 2 7 5 6 4 3 1 2 6 5 7 1 3 4 2 7 3 1 5 6 4 2 7 6 4 5 3 1 2 7 6 5 4 3 1 2 5 3 4 1 7 6 2 3 4 7 1 6 5 2 6 4 7 5 3 1 2 7 5 3 4 1 6 2 7 6 1 5 3 4 2 7 5 3 1 6 4 2 6 5 4 7 3 1 2 7 6 5 4 3 1 2 7 6 4 5 1 3 2 5 6 7 4 3 1 2 6 5 7 4 1 3 2 6 7 4 5 1 3 2 7 6 5 4 3 1 2 6 5 4 ...
result:
ok 286 cases.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 01000 10100 01010 00100 00000 9 001101110 001010001 110100110 101010000 010100011 100000000 101000000 101010001 010010010 4 0000 0011 0101 0110 8 00100101 00101100 11000011 00001111 01010101 11011000 00110000 10111000 9 000000001 001101000 010000100 010000111 000000000 010000111 001101010 00010110...
output:
5 3 1 4 2 5 7 8 6 9 4 1 3 2 3 1 4 2 8 1 6 7 5 3 4 2 9 8 7 6 5 4 3 1 2 4 1 3 2 3 1 5 4 6 2 6 5 3 1 4 2 6 4 3 5 7 1 2 6 4 5 1 7 3 2 9 7 5 10 6 8 3 4 1 2 5 8 9 4 3 6 10 7 1 2 4 3 5 6 1 2 7 6 3 5 4 1 8 2 3 7 4 9 8 5 6 1 2 1 3 2 3 1 2 6 4 1 5 3 2 4 3 6 1 5 7 2 1 3 2 1 3 2 3 1 4 5 2 3 6 4 5 1 2 6 4 8 3 7 ...
result:
ok 322 cases.
Test #8:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
10 0010001000 0010011001 1101101001 0010111000 0011000110 0101001100 1111010001 0000110011 0000100101 0110001110 10 0000000010 0000001001 0000001101 0000100000 0001010111 0000101011 0110010100 0010101000 1000110000 0110110000 10 0110010111 1011111110 1100101010 0100001101 0110001111 1100001010 01111...
output:
7 8 1 9 10 3 5 4 6 2 9 6 10 5 8 7 4 3 1 2 9 8 6 5 10 4 7 3 1 2 8 4 3 7 9 10 6 1 5 2 8 6 4 5 10 7 9 1 3 2 8 4 6 10 7 1 5 9 3 2 6 10 3 9 8 7 1 5 4 2 10 5 9 8 7 6 4 3 1 2 9 5 7 10 8 4 3 1 6 2 10 9 7 8 6 3 5 4 1 2 10 3 9 7 6 8 1 5 4 2 3 1 9 6 8 10 7 5 4 2 8 6 7 4 9 10 3 1 5 2 5 3 9 8 10 7 6 1 4 2 10 9 8...
result:
ok 200 cases.
Test #9:
score: 0
Accepted
time: 3ms
memory: 3564kb
input:
10 0110101100 1010100111 1101100101 0010111010 1111001010 0001000000 1001100111 1110001001 0101101000 0110001100 10 0111110111 1001111100 1001100100 1110101111 1111001010 1100001000 0101110100 1111001010 1001100100 1001000000 10 0100000111 1011111001 0100001111 0100100110 0101011100 0100100110 01101...
output:
10 9 8 5 6 7 4 3 1 2 8 10 6 9 7 5 4 3 1 2 10 7 6 4 3 5 9 8 1 2 9 6 5 10 8 3 4 7 1 2 9 8 10 5 7 6 4 1 3 2 10 5 3 7 6 8 4 9 1 2 10 8 9 7 6 4 5 3 1 2 10 8 9 7 5 6 4 1 3 2 8 9 10 7 4 3 5 1 6 2 9 8 6 10 3 7 5 1 4 2 6 3 1 10 9 8 7 4 5 2 7 3 4 6 5 8 9 10 1 2 7 4 8 6 9 3 5 10 1 2 7 9 3 8 5 10 4 6 1 2 9 6 10...
result:
ok 200 cases.
Test #10:
score: -100
Wrong Answer
time: 11ms
memory: 3588kb
input:
20 00011111000111100010 00100111111000000010 01011011101000100111 10100010000100000010 10100100000010101101 11001001010010000111 11110000010000111001 11100100111000010101 01100001011101100010 01000111100111011001 01100001100111111111 10010000111001010000 10001100011001001000 10000000111110111010 101...
output:
20 18 17 16 15 14 12 4 7 3 5 13 6 10 8 11 19 9 1 2 17 16 19 14 15 13 18 10 11 7 6 8 1 3 5 9 12 4 2 18 12 22 21 19 7 15 13 4 9 20 3 11 8 16 14 6 5 17 10 1 2 9 10 3 4 8 13 12 11 7 6 5 1 2 23 30 28 29 20 22 21 19 13 17 18 10 12 15 5 11 3 16 4 6 14 9 8 7 1 2 1 1 1 1 20 22 19 18 15 17 21 16 13 14 12 11 9...
result:
wrong answer case #5: not a permutation