Submission #424347

#TimeUsernameProblemLanguageResultExecution timeMemory
424347MarcoMeijerScales (IOI15_scales)C++14
100 / 100
584 ms5268 KiB
#include "scales.h" #include <bits/stdc++.h> using namespace std; // macros typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef pair<ll, ll> lll; typedef tuple<int, int, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<ll> vll; typedef vector<lll> vlll; #define REP(a,b,c) for(int a=int(b); a<int(c); a++) #define RE(a,c) REP(a,0,c) #define RE1(a,c) REP(a,1,c+1) #define REI(a,b,c) REP(a,b,c+1) #define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--) #define FOR(a,b) for(auto& a : b) #define all(a) a.begin(), a.end() #define INF 1e9 #define EPS 1e-9 #define pb push_back #define popb pop_back #define fi first #define se second #define sz size() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); // output template<class T1, class T2> void OUT(const pair<T1,T2>& x); template<class T> void OUT(const vector<T>& x); template<class T> void OUT(const T& x) {cerr << x;} template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); } template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);} template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);} template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); } template<class H> void OUTLS(const H& h) {OUTL(h); } template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); } vector<vi> possible, queries; int qMem[120][720]; map<vi,int> mem[10]; int getRes(vi v, vi q) { if(q[0] <= 3) { int cnt = 0; RE(i,6) { RE1(j,3) if(v[i] == q[j]) cnt++; if(cnt == q[0]) { RE1(j,3) if(v[i] == q[j]) return j-1; } } } else { int beg = 0; RE(i,6) { if(beg) RE1(j,3) if(v[i] == q[j]) return j-1; if(v[i] == q[4]) beg = 1; if(i == 5) i = -1; } } return -1; } int askQuery(vi q) { if(q[0] == 1) return getLightest (q[1],q[2],q[3]); if(q[0] == 2) return getMedian (q[1],q[2],q[3]); if(q[0] == 3) return getHeaviest (q[1],q[2],q[3]); if(q[0] == 4) return getNextLightest(q[1],q[2],q[3],q[4]); return -1; } void init(int T) { vi v = {1,2,3,4,5,6}; RE(i,720) { possible.pb(v); next_permutation(all(v)); } RE1(i,6) RE1(j,i-1) RE1(k,j-1) { RE1(l,3) queries.pb({l,i,j,k}); RE1(l,k-1) { queries.pb({4,j,k,l,i}); queries.pb({4,i,k,l,j}); queries.pb({4,i,j,l,k}); queries.pb({4,i,j,k,l}); } } RE(i,120) RE(j,720) qMem[i][j] = getRes(possible[j], queries[i]); } int getNext(vi a, int depth) { auto it = mem[depth].find(a); if(it != mem[depth].end()) return it->second; if(depth == 0) return a.size() <= 1 ? 0 : -1; vi inter; int mn = 1e9; RE(i,120) { int cnt[]={0,0,0}; FOR(j,a) cnt[qMem[i][j]]++; sort(cnt,cnt+3); if(mn > cnt[2]) mn = cnt[2], inter.clear(); if(mn == cnt[2]) inter.pb(i); } FOR(i,inter) { vi nxt[3]; FOR(j,a) nxt[qMem[i][j]].pb(j); bool pos = true; RE(j,3) if(getNext(nxt[j],depth-1) == -1) pos = false; if(!pos) continue; return mem[depth][a] = i; } return mem[depth][a] = -1; } void orderCoins() { vi a; RE(i,720) a.pb(i); int depth = 6; while(a.size() != 1) { int nxt = getNext(a,depth--); int res = askQuery(queries[nxt]); vi na; FOR(i,a) if(queries[nxt][qMem[nxt][i]+1] == res) na.pb(i); a = na; } int W[] = {0, 0, 0, 0, 0, 0}; RE(i,6) W[i] = possible[a[0]][i]; answer(W); }

Compilation message (stderr)

scales.cpp: In function 'void init(int)':
scales.cpp:74:15: warning: unused parameter 'T' [-Wunused-parameter]
   74 | void init(int T) {
      |           ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...