# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140467 | MrBrionix | Unscrambling a Messy Bug (IOI16_messy) | C++14 | 4 ms | 636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <cstdlib>
#include <iostream>
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
/*
namespace helper {
set<string> set_;
bool compiled = false;
int n;
vector<int> p;
int w;
int r;
int read_int() {
int x;
cin >> x;
return x;
}
}
using namespace helper;
// A convenience function.
int get_p(int i) {
int ret = p[i];
return ret;
}
void wa() {
printf("WA\n");
exit(0);
}
bool check(const string& x) {
if ((int)x.length() != n) {
return false;
}
for (int i = 0; i < n; i++) {
if (x[i] != '0' && x[i] != '1') {
return false;
}
}
return true;
}
void add_element(string x) {
//cout<<x<<endl;
if (--w < 0 || compiled || !check(x)) {
wa();
}
set_.insert(x);
}
bool check_element(string x) {
if (--r < 0 || !compiled || !check(x)) {
wa();
}
return set_.count(x);
}
void compile_set() {
if (compiled) {
wa();
}
compiled = true;
set<string> compiledSet;
string compiledElement = string(n, ' ');
for (set<string>::iterator it = set_.begin(); it != set_.end(); it++) {
string s = *it;
for (int i = 0; i < n; i++) {
compiledElement[i] = s[get_p(i)];
}
compiledSet.insert(compiledElement);
}
set_ = compiledSet;
}
*/
vector<int> sol,v[16][200],opz[16][200];
string vuota,s;
int cont;
vector<int> restore_permutation(int n, int w, int r) {
for(int i=0;i<n;i++){
vuota.push_back('0');
v[0][0].push_back(i);
}
s=vuota;
for(int i=0;v[i][0].size()>1;i++){
for(int j=0;j<(1<<i);j++){
for(int z=0;z<(v[i][j].size()/2);z++){
v[i+1][j*2].push_back(v[i][j][z]);
v[i+1][j*2+1].push_back(v[i][j][z+(v[i][j].size()/2)]);
}
}
}
for(int i=0;i<n/2;i++){
s[i]='1';
add_element(s);
s[i]='0';
}
for(int i=1;v[i][0].size()>1;i++){
for(int j=0;j<(1<<i);j++){
s=vuota;
for(int z=0;z<v[i][(j+1)%(1<<i)].size();z++){
s[v[i][(j+1)%(1<<i)][z]]='1';
}
for(int z=0;z<(v[i][j].size()/2);z++){
s[v[i][j][z]]='1';
add_element(s);
s[v[i][j][z]]='0';
}
}
}
compile_set();
s=vuota;
for(int i=0;i<v[0][0].size();i++){
s[i]='1';
if(check_element(s))
opz[1][0].push_back(i);
else
opz[1][1].push_back(i);
s[i]='0';
}
cont=1;
//cout<<"a"<<endl;
for(;opz[cont][0].size()>1;cont++){
for(int j=0;j<(1<<cont);j++){
s=vuota;
for(int z=0;z<opz[cont][(j+1)%(1<<cont)].size();z++){
s[opz[cont][(j+1)%(1<<cont)][z]]='1';
//cout<<z<<" z"<<endl;
}
for(int z=0;z<opz[cont][j].size();z++){
s[opz[cont][j][z]]='1';
if(check_element(s))
opz[cont+1][j*2].push_back(opz[cont][j][z]);
else
opz[cont+1][j*2+1].push_back(opz[cont][j][z]);
s[opz[cont][j][z]]='0';
}
//cout<<j<<" j"<<endl;
}
//cout<<cont<<endl;
}
sol.resize(n);
for(int i=0;i<n;i++){
sol[opz[cont][i][0]]=i;
}
return sol;
}
/*
int main() {
n = read_int();
w = read_int();
r = read_int();
p = vector<int>(n);
for (int i = 0; i < n; i++) {
p[i] = read_int();
}
vector<int> answer = restore_permutation(n, w, r);
if (answer.size() != n) {
printf("WA\n");
return 0;
}
printf("%d", answer[0]);
for (int i = 1; i < n; i++) {
printf(" %d", answer[i]);
}
printf("\n");
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |