QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377667#2833. HamiltonJerrywangRE 0ms0kbC++141.3kb2024-04-05 16:34:452024-04-05 16:34:46

Judging History

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

  • [2024-04-05 16:34:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-05 16:34:45]
  • 提交

answer

// Title:  Hamilton
// Source: QOJ2833
// Author: Jerrywang
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define ll long long
#define rep(i, s, t) for(int i=s; i<=t; ++i)
#define debug(x) cerr<<#x<<":"<<x<<endl;
const int N=2005;
using namespace std;

int n, g[N][N]; vector<int> a;
void ins(int i, int x)
{
    a.insert(a.begin()+i, x);
}
void solve()
{
    rep(i, 1, n) rep(j, 1, n) scanf("%1d", &g[i][j]);
    a.clear();
    rep(i, 1, n)
    {
        bool f=0;
        rep(j, 1, n) if(g[i][j])
        {
            a.push_back(i), a.push_back(j), f=1; break;
        }
        if(f) break;
    }
    rep(i, 1, n)
    {
        int k=-1;
        for(int x:a) if(x==i) k=1;
        if(k==1) continue;
        rep(j, 1, a.size()-2)
        {
            if(g[a[j-1]][a[j]] && !g[a[j]][a[j+1]])
            {
                k=j; break;
            }
        }
        if(k==-1) a.push_back(i);
        else if(g[a[k]][i]==0) ins(k, i);
        else ins(k+1, i);
    }
    if(g[a[n-1]][a[0]]==1)
        a.insert(a.begin(), a[n-1]), a.pop_back();
    for(int x:a) printf("%d ", x);
    puts("");
}
int main()
{
    #ifdef Jerrywang
    freopen("E:/OI/in.txt", "r", stdin);
    #endif
    while(~scanf("%d", &n)) solve();
    
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

3
001
000
100
4
0000
0000
0000
0000

output:


result: