답안 #785678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
785678 2023-07-17T12:06:00 Z I_Love_EliskaM_ 정렬하기 (IOI15_sorting) C++14
36 / 100
1 ms 724 KB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back

int ok(vector<int>&a) {
    forn(i,a.size()) if (a[i]!=i) return 0;
    return 1;
}

struct DSU {
    vector<int> p,sz;
    DSU(int n) {
        forn(i,n) p.pb(i), sz.pb(1);
    }
    int get(int u) {
        return p[u]==u?u:get(p[u]);
    }
    void uni(int u, int v) {
        u=get(u), v=get(v);
        if (u==v) return;
        if (sz[u]<sz[v]) swap(u,v);
        sz[u]+=sz[v];
        p[v]=u;
    }
};

int findSwapPairs(int n, int _p[], int m, int _x[], int _y[], int p[], int q[]) {
    vector<int> a; 
    forn(i,n) a.pb(_p[i]);
    if (ok(a)) return 0;

    vector<int> x,y;
    forn(i,m) x.pb(_x[i]), y.pb(_y[i]);
    x.pb(0), y.pb(0);

    int z=1;
    forn(i,m) z&=(x[i]==y[i])&&(x[i]==0);
    if (z) {
        int t=0;
        while (!ok(a)) {
            forn(i,n) {
                if (a[i]!=i) {
                    p[t]=i, q[t]=a[i];
                    swap(a[i],a[a[i]]);
                    ++t;
                    break;
                }
            }
        }
        return t;
    }
    z=1;
    forn(i,m) z&=(x[i]==0) && (y[i]==1);
    if (z) {
        int t=0;
        while(1) {
            swap(a[0],a[1]);
            int b=0;
            vector<int> pos(n);
            forn(i,n) pos[a[i]]=i;
            forn(i,n) {
                if (i<2) continue;
                if (a[i]!=i) {
                    p[t]=i, q[t]=pos[i];
                    swap(a[i],a[pos[i]]);
                    ++t;
                    b=1;
                    break;
                }
            }
            if (b) continue;
            if (ok(a)) {
                p[t]=0, q[t]=0; ++t;
                return t;
            } else {
                p[t]=0, q[t]=1; ++t;
                return t;
            }
        }
        return t;
    }
    exit(1);
    return 0;

}

Compilation message

sorting.cpp: In function 'int ok(std::vector<int>&)':
sorting.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
    8 |     forn(i,a.size()) if (a[i]!=i) return 0;
      |          ~~~~~~~~~~             
sorting.cpp:8:5: note: in expansion of macro 'forn'
    8 |     forn(i,a.size()) if (a[i]!=i) return 0;
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Runtime error 1 ms 724 KB Execution failed because the return code was nonzero
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -