답안 #1079651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079651 2024-08-28T19:55:12 Z ALeonidou Unscrambling a Messy Bug (IOI16_messy) C++17
49 / 100
1 ms 440 KB
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;

#define ll int
#define F first
#define S second
#define sz(x) (ll)x.size()
#define pb push_back

typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;

#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;

void printVct(vi &v){
    for (ll i= 0; i<sz(v); i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}

mt19937 rng;
void init_rand(){
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());
}

vi gen_rand_permutation(ll n){
    vi v;
    for (ll i =0; i<n; i++){
        v.pb(i);
    }
    shuffle(v.begin(), v.end(), rng);
    return v;
}

vi restore_permutation(int n, int w, int r) {
    init_rand();

    string s;
    for (ll i =0; i<n; i++) s.pb('0');
    for (ll i =0; i<n-1; i++){
        s[i] = '1';
        add_element(s);
    }

    compile_set();

    vector <string> vs(n-1);
    string tmp; 
    for (ll i =0; i<n; i++) tmp.pb('0');

    for (ll i = 0; i<n; i++){
        vi p = gen_rand_permutation(n);
        for (ll j =0; j<n; j++){
            ll idx = p[j];
            if (tmp[idx] == '1') continue;
            tmp[idx] = '1';
            bool x = check_element(tmp);
            if (x){
                vs[i] = tmp;
                break;
            }
            else{
                tmp[idx] = '0';
            }
        }
    }

    vi ans(n);
    vi vis(n);
    for (ll i =0; i<n-1; i++){
        string c = vs[i];
        ll init_pos = i, final_pos = -1;
        for (ll j =0; j<n; j++){
            if (c[j] == '1' && !vis[j]){
                final_pos = j;
                break;
            }
        }
        // dbg2(init_pos, final_pos);
        vis[final_pos] = 1;
        ans[final_pos] = init_pos;
    }
    for (ll i=0; i<n; i++){
        if (!vis[i]){
            ans[i] = n-1;
            break;
        }
    }

    return ans;
}

/*
4 16 16
2 1 3 0

8 256 256
2 1 3 4 7 0 6 5

8 256 256
2 1 3 4 7 0 6 5

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 8
2 Correct 1 ms 348 KB n = 8
3 Correct 1 ms 348 KB n = 8
4 Correct 0 ms 348 KB n = 8
5 Correct 0 ms 348 KB n = 8
6 Correct 0 ms 348 KB n = 8
7 Correct 0 ms 348 KB n = 8
8 Correct 0 ms 348 KB n = 8
9 Correct 1 ms 348 KB n = 8
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 0 ms 348 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 0 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 0 ms 348 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 1 ms 348 KB n = 32
8 Correct 1 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 0 ms 348 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 0 ms 348 KB n = 32
15 Correct 0 ms 440 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 32
2 Correct 1 ms 348 KB n = 32
3 Correct 0 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 0 ms 344 KB n = 32
6 Correct 0 ms 344 KB n = 32
7 Correct 1 ms 348 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 1 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 1 ms 348 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 0 ms 348 KB n = 32
15 Correct 1 ms 348 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB grader returned WA
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB grader returned WA
2 Halted 0 ms 0 KB -