답안 #419251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419251 2021-06-06T15:26:22 Z mat_v Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
4 ms 496 KB
#include <bits/stdc++.h>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define pb push_back
#include "messy.h"

using namespace std;

int N;

void dodaj(int l, int r){
    if(l == r)return;
    ff(i,0,(r-l+1)/2 - 1){
        string x="";
        ff(j,0,N - 1){
            if(j < l || j > r)x += '1';
            else{
                if(j == i+l)x += '1';
                else x += '0';
            }
        }
        add_element(x);
    }
    int mid = (l + r) / 2;
    dodaj(l,mid);
    dodaj(mid + 1, r);
}

int slika[1005];
bool ima[1005];
int sol[1005];


void resi(int l, int r, vector<int> s){

    if(l == r){
        slika[l] = s[0];
        return;
    }
    vector<int> gde;
    ff(i,0,N-1)ima[i] = 0;
    for(auto c:s)ima[c] = 1;
    vector<int> pola;
    ff(i,0,r-l){
        string x = "";
        int kol = 0;
        ff(j,0,N-1){
            if(!ima[j])x += '1';
            else{
                if(j == s[i])x += '1';
                else x += '0';
                kol++;
            }
        }
        //check(x);
        if(check_element(x))pola.pb(s[i]);
    }
    vector<int> druga;
    ff(i,0,N-1)ima[i] = 0;
    for(auto c:pola)ima[c] = 1;
    for(auto c:s)if(!ima[c])druga.pb(c);
    int mid = (l + r) / 2;
    resi(l,mid,pola);
    resi(mid + 1,r,druga);
}

std::vector<int> restore_permutation(int n, int w, int r) {
    N = n;
    dodaj(0,n - 1);
    compile_set();
    vector<int> v;
    ff(i,0,n-1)v.pb(i);
    resi(0,n-1,v);

    vector<int> ans;
    ff(i,0,N-1)sol[slika[i]] = i;
    ff(i,0,N-1)slika[i] = sol[i];
    ff(i,0,N-1)ans.pb(slika[i]);
    return ans;
}

Compilation message

messy.cpp: In function 'void dodaj(int, int)':
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:14:5: note: in expansion of macro 'ff'
   14 |     ff(i,0,(r-l+1)/2 - 1){
      |     ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:16:9: note: in expansion of macro 'ff'
   16 |         ff(j,0,N - 1){
      |         ^~
messy.cpp: In function 'void resi(int, int, std::vector<int>)':
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:42:5: note: in expansion of macro 'ff'
   42 |     ff(i,0,N-1)ima[i] = 0;
      |     ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:45:5: note: in expansion of macro 'ff'
   45 |     ff(i,0,r-l){
      |     ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:48:9: note: in expansion of macro 'ff'
   48 |         ff(j,0,N-1){
      |         ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:60:5: note: in expansion of macro 'ff'
   60 |     ff(i,0,N-1)ima[i] = 0;
      |     ^~
messy.cpp: In function 'std::vector<int> restore_permutation(int, int, int)':
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:73:5: note: in expansion of macro 'ff'
   73 |     ff(i,0,n-1)v.pb(i);
      |     ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:77:5: note: in expansion of macro 'ff'
   77 |     ff(i,0,N-1)sol[slika[i]] = i;
      |     ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:78:5: note: in expansion of macro 'ff'
   78 |     ff(i,0,N-1)slika[i] = sol[i];
      |     ^~
messy.cpp:4:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    4 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
messy.cpp:79:5: note: in expansion of macro 'ff'
   79 |     ff(i,0,N-1)ans.pb(slika[i]);
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB n = 8
2 Correct 1 ms 204 KB n = 8
3 Correct 1 ms 204 KB n = 8
4 Correct 0 ms 204 KB n = 8
5 Correct 1 ms 204 KB n = 8
6 Correct 1 ms 204 KB n = 8
7 Correct 0 ms 204 KB n = 8
8 Correct 0 ms 204 KB n = 8
9 Correct 1 ms 204 KB n = 8
10 Correct 0 ms 204 KB n = 8
11 Correct 1 ms 204 KB n = 8
12 Correct 1 ms 204 KB n = 8
13 Correct 0 ms 204 KB n = 8
14 Correct 0 ms 204 KB n = 8
15 Correct 0 ms 204 KB n = 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB n = 32
2 Correct 1 ms 204 KB n = 32
3 Correct 1 ms 204 KB n = 32
4 Correct 1 ms 204 KB n = 32
5 Correct 1 ms 204 KB n = 32
6 Correct 1 ms 204 KB n = 32
7 Correct 1 ms 204 KB n = 32
8 Correct 1 ms 204 KB n = 32
9 Correct 1 ms 300 KB n = 32
10 Correct 1 ms 204 KB n = 32
11 Correct 1 ms 296 KB n = 32
12 Correct 1 ms 204 KB n = 32
13 Correct 1 ms 204 KB n = 32
14 Correct 1 ms 204 KB n = 32
15 Correct 1 ms 204 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB n = 32
2 Correct 1 ms 204 KB n = 32
3 Correct 1 ms 224 KB n = 32
4 Correct 1 ms 204 KB n = 32
5 Correct 1 ms 204 KB n = 32
6 Correct 1 ms 204 KB n = 32
7 Correct 1 ms 288 KB n = 32
8 Correct 1 ms 204 KB n = 32
9 Correct 1 ms 300 KB n = 32
10 Correct 1 ms 204 KB n = 32
11 Correct 1 ms 204 KB n = 32
12 Correct 1 ms 204 KB n = 32
13 Correct 1 ms 204 KB n = 32
14 Correct 1 ms 204 KB n = 32
15 Correct 1 ms 204 KB n = 32
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB n = 128
2 Correct 3 ms 460 KB n = 128
3 Correct 3 ms 460 KB n = 128
4 Correct 3 ms 460 KB n = 128
5 Correct 3 ms 460 KB n = 128
6 Correct 4 ms 460 KB n = 128
7 Correct 3 ms 460 KB n = 128
8 Correct 3 ms 460 KB n = 128
9 Correct 3 ms 460 KB n = 128
10 Correct 3 ms 460 KB n = 128
11 Correct 3 ms 460 KB n = 128
12 Correct 3 ms 460 KB n = 128
13 Correct 3 ms 460 KB n = 128
14 Correct 3 ms 492 KB n = 128
15 Correct 3 ms 460 KB n = 128
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 460 KB n = 128
2 Correct 3 ms 460 KB n = 128
3 Correct 3 ms 460 KB n = 128
4 Correct 3 ms 460 KB n = 128
5 Correct 3 ms 496 KB n = 128
6 Correct 3 ms 460 KB n = 128
7 Correct 3 ms 460 KB n = 128
8 Correct 3 ms 460 KB n = 128
9 Correct 3 ms 460 KB n = 128
10 Correct 3 ms 460 KB n = 128
11 Correct 3 ms 460 KB n = 128
12 Correct 3 ms 460 KB n = 128
13 Correct 3 ms 460 KB n = 128
14 Correct 3 ms 420 KB n = 128
15 Correct 3 ms 424 KB n = 128