QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#26033#2833. HamiltonHakujitsuWA 3ms3612kbC++2.0kb2022-04-05 22:11:562022-04-29 02:45:57

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 02:45:57]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3612kb
  • [2022-04-05 22:11:56]
  • 提交

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 zero = 0;
        int one = 0;
        for (int j = 1; j < res.size(); j += 1) {
            if(mp[res[j - 1]][res[j]] == '0') zero += 1;
            else one += 1;
        }
        if(zero == 0 || one == 0) {
            for (int j = 1; j < res.size(); j += 1) {
                if(mp[i][res[j]] == mp[res[j]][res[j - 1]]) {
                    res.insert(res.begin() + ((j + 1) % int(res.size())), i);
                    break;
                }
                if(mp[i][res[j - 1]] == mp[res[j - 1]][res[j]]) {
                    res.insert(res.begin() + j, i);
                }
            }
            continue;
        }
        int j = 0;
        for (; j + 1 < res.size(); j += 1) {
            if(mp[res[j]][res[j + 1]] == '1') {
                break;
            }
        }
        if(mp[res[j - 1]][i] == '0' || mp[res[j]][i] == '1') {
            res.insert(res.begin() + j, i);
            continue;
        }
        if(mp[res[j]][i] == '0' || mp[res[j + 1]][i] == '1'){
            res.insert(res.begin() + j + 1, i);
            continue;
        }
        assert(0);
    }
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3612kb

input:

3
001
000
100
4
0000
0000
0000
0000

output:

1 2 3
1 2 4 3

result:

ok 2 cases.

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3552kb

input:

3
000
000
000
3
010
100
000
3
011
100
100
3
011
101
110

output:

1 2 3
1 2 3
1 2 3
1 2 3

result:

wrong answer case #3: found 2 indices