QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#26035 | #2833. Hamilton | Hakujitsu | WA | 3ms | 3572kb | C++ | 2.1kb | 2022-04-05 22:32:24 | 2022-04-29 02:46:06 |
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;
}
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;
}
auto get = [&](int x) {
x = (x + res.size()) % res.size();
return res[x];
};
auto check = [&](int pos) {
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 != res.size()) cur += c1 != c2;
//debug(pos, cur);
return cur <= 1;
};
for (int j = -1; j < int(res.size()); j += 1) {
if(check(j + 1)) {
//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: 3572kb
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: -100
Wrong Answer
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 3 1 2 3 1 2 3 1 2
result:
wrong answer case #2: found 2 indices