QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#51626#4632. Card Sharksealnot123#WA 5ms8484kbC++2.0kb2022-10-03 03:58:382022-10-03 03:58:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-03 03:58:40]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:8484kb
  • [2022-10-03 03:58:38]
  • 提交

answer

#include<bits/stdc++.h>

#define x first
#define y second
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define ROF(i,a,b) for(int i=(a); i>=(b); --i)
#define pb push_back
#define eb emplace_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int N = 200005;
vpii g[N];
int state[N];
char s[1000005];
vi ans;
int deg[N];

void dfs(int u) {
    if(state[u] < sz(g[u])) {
        int now = state[u];
        state[u]++;
        pii e = g[u][now];
        dfs(e.y);
        ans.eb(e.x);
    }
}

void solve() {
    int n, m, p;
    bool valid = true;
    scanf("%d %d %d",&n,&m,&p);
    rep(i,0,n){
        scanf(" %s",s);
        vi ones;
        int len = strlen(s);
        rep(j, 0, len) {
            if(s[j] == '1') ones.eb(j);
        }
        if(ones[0] > m-1 || len-ones.back() > m) {
            valid = false;
            continue;
        }
        rep(j, 0, sz(ones)-1) {
            if(ones[j+1]-ones[j] != m) {
                valid = false;
                break;
            }
        }
        if(!valid) continue;
        int a = (m-ones[0]-1)%m;
        int b = len-ones.back()-1;
        g[a].eb(i,b);
        deg[a]++;
        deg[b]--;
    }
    if(!valid) {
        printf("-1\n");
        return ;
    }
    int st = m-p;
    rep(i, 0, m) {
        sort(all(g[i]));
    }

    rep(i, 0, m){
        if(deg[i]) {
            valid = false;
            break;
        }
    }
    if(!valid) {
        printf("-1\n");
        return ;
    }

    dfs(st);
    rep(i, 0, m) {
        if(state[i] != sz(g[i])) {
            valid = false;
            break;
        }
    }

    if(!valid) {
        printf("-1\n");
        return ;
    }

    reverse(all(ans));
    rep(i, 0, n) {
        printf("%d ",ans[i]+1);
    }
    puts("");
}

int main() {
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 8484kb

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: 5ms
memory: 8432kb

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: 2ms
memory: 8440kb

input:

1 5 3
001000010000100

output:

1 

result:

ok single line: '1 '

Test #4:

score: 0
Accepted
time: 4ms
memory: 8300kb

input:

2 5 3
01000
00010

output:

-1

result:

ok single line: '-1'

Test #5:

score: 0
Accepted
time: 5ms
memory: 8368kb

input:

1 5 3
11111

output:

-1

result:

ok single line: '-1'

Test #6:

score: -100
Wrong Answer
time: 5ms
memory: 8464kb

input:

10 5 3
000010000100
0001000010000100001
000100
00010
00010000100
0010
00001000010000100001000010
00010
001
001000010

output:

-1

result:

wrong answer 1st lines differ - expected: '6 2 1 9 7 3 10 4 8 5', found: '-1'