제출 #805810

#제출 시각아이디문제언어결과실행 시간메모리
805810Ozy죄수들의 도전 (IOI22_prison)C++17
56 / 100
11 ms1748 KiB
#include "prison.h" #include <bits/stdc++.h> using namespace std; #define lli long long int #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define rep(i,a,b) for(int i = (a); i <= (b); i++) #define repa(i,a,b) for(int i = (a); i >= (b); i--) #define pll pair<lli,lli> #define MAX 500 lli n,bolsa,act,mitad,w; vector< vector<int> > res; vector<int> trash; vector<pll> rangos,mover; lli escribe(lli b) { b *= (-1); b -= 1; return b; } std::vector<std::vector<int>> devise_strategy(int N) { // dividir (1,2) para pregutar por B y (3,4) para volver a preguntar por A //inicializa el s[0][0] n = N; res.push_back(trash); res[0].resize(n+1); res[0][0] = 0; w = (n+1)/2; rep(i,1,n) { if (i <= w) res[0][i] = 2; //abajo else res[0][i] = 1; //arriba } rangos.push_back({1,n}); bolsa = 0; act = 1; while (!rangos.empty()) { bolsa ^= 1; res.push_back(trash); res[act].resize(n+1); res.push_back(trash); res[act+1].resize(n+1); rep(pos,act,act+1) { res[pos][0] = bolsa; for(auto r : rangos) { mitad = (r.second+r.first)/2; rep(i,r.first,mitad) {// mitad de abajo if (pos&1) res[pos][i] = escribe(bolsa); else { w = (r.first+mitad)/2; if (i <= w) res[pos][i] = pos+2; else res[pos][i] = pos+1; } } rep(i,mitad+1,r.second) { //mitad de arriba if (pos&1) { w = (r.second + mitad + 1)/2; if (i <= w) res[pos][i] = pos+3; else res[pos][i] = pos+2; } else res[pos][i] = escribe(bolsa^1); } } } swap(mover,rangos); rangos.clear(); for(auto m : mover) { if (m.first == m.second) continue; if (m.first + 1 == m.second) continue; mitad = (m.first + m.second)/2; rangos.push_back({m.first,mitad}); rangos.push_back({mitad+1,m.second}); } act += 2; } act = res.size()-1; rep(i,0,act) { rep(j,1,n) { if (res[i][j] > act) res[i][j] = -1; } } return res; } // tener cuidado ya que la implementacion puede dejar valores mayores a x, eso es un wa (sube las x)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...