# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
639000 |
2022-09-08T07:30:19 Z |
ggoh |
Scales (IOI15_scales) |
C++14 |
|
233 ms |
344 KB |
#include "scales.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
typedef long long lint;
int ans,rev[720][7],sz;
int c[7],a[7];
void br(int p)
{
if(p==7)
{
for(int i=1;i<=6;i++)
{
rev[sz][i]=a[i];
}
sz++;
return ;
}
for(int i=1;i<=6;i++)
{
if(!c[i])
{
c[i]=1;
a[p]=i;
br(p+1);
a[p]=0;
c[i]=0;
}
}
}
void init(int T) {
sz=0;
br(1);
}
int f(vector<int> X)
{
int n=sz(X);
if(n<=1)
{
return 1;
}
int u=(n+2)/3;
for(int i=1;i<=6;i++)
{
for(int j=i+1;j<=6;j++)
{
for(int k=j+1;k<=6;k++)
{
vector<int>Xi;
vector<int>Xj;
vector<int>Xk;
//getHeaviest
for(auto &x:X)
{
if(rev[x][i]>rev[x][j] && rev[x][i]>rev[x][k])Xi.push_back(x);
if(rev[x][j]>rev[x][i] && rev[x][j]>rev[x][k])Xj.push_back(x);
if(rev[x][k]>rev[x][i] && rev[x][k]>rev[x][j])Xk.push_back(x);
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))return 1;
}
//getMedian
Xi.clear();
Xj.clear();
Xk.clear();
for(auto &x:X)
{
if((rev[x][i]>rev[x][j] && rev[x][i]<rev[x][k]) || (rev[x][i]<rev[x][j] && rev[x][i]>rev[x][k]))Xi.push_back(x);
if((rev[x][j]>rev[x][i] && rev[x][j]<rev[x][k])||(rev[x][j]<rev[x][i] && rev[x][j]>rev[x][k]))Xj.push_back(x);
if((rev[x][k]>rev[x][i] && rev[x][k]<rev[x][j])||(rev[x][k]<rev[x][i] && rev[x][k]>rev[x][j]))Xk.push_back(x);
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))return 1;
}
//getLightest
Xi.clear();
Xj.clear();
Xk.clear();
for(auto &x:X)
{
if(rev[x][i]<rev[x][j] && rev[x][i]<rev[x][k])Xi.push_back(x);
if(rev[x][j]<rev[x][i] && rev[x][j]<rev[x][k])Xj.push_back(x);
if(rev[x][k]<rev[x][i] && rev[x][k]<rev[x][j])Xk.push_back(x);
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))return 1;
}
//getNextLightest
for(int l=1;l<=6;l++)
{
if(l!=i && l!=j && l!=k)
{
Xi.clear();
Xj.clear();
Xk.clear();
for(auto &x:X)
{
if(rev[x][l]>rev[x][i]&&rev[x][l]>rev[x][j]&&rev[x][l]>rev[x][k])
{
if(rev[x][i]<rev[x][j] && rev[x][i]<rev[x][k])Xi.push_back(x);
if(rev[x][j]<rev[x][i] && rev[x][j]<rev[x][k])Xj.push_back(x);
if(rev[x][k]<rev[x][i] && rev[x][k]<rev[x][j])Xk.push_back(x);
}
else
{
if(rev[x][l]<rev[x][i] && !(rev[x][l]<rev[x][j] && rev[x][j]<rev[x][i]) && !(rev[x][l]<rev[x][k] && rev[x][k]<rev[x][i]))Xi.push_back(x);
if(rev[x][l]<rev[x][j] && !(rev[x][l]<rev[x][i] && rev[x][i]<rev[x][j]) && !(rev[x][l]<rev[x][k] && rev[x][k]<rev[x][j]))Xj.push_back(x);
if(rev[x][l]<rev[x][k] && !(rev[x][l]<rev[x][i] && rev[x][i]<rev[x][k]) && !(rev[x][l]<rev[x][j] && rev[x][j]<rev[x][k]))Xk.push_back(x);
}
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))return 1;
}
}
}
}
}
}
return 0;
}
void g(vector<int>X)
{
int n=sz(X);
if(n==1)
{
ans=X[0];
return ;
}
int u=(n+2)/3;
for(int i=1;i<=6;i++)
{
for(int j=i+1;j<=6;j++)
{
for(int k=j+1;k<=6;k++)
{
vector<int>Xi;
vector<int>Xj;
vector<int>Xk;
//getHeaviest
for(auto &x:X)
{
if(rev[x][i]>rev[x][j] && rev[x][i]>rev[x][k])Xi.push_back(x);
if(rev[x][j]>rev[x][i] && rev[x][j]>rev[x][k])Xj.push_back(x);
if(rev[x][k]>rev[x][i] && rev[x][k]>rev[x][j])Xk.push_back(x);
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))
{
int t=getHeaviest(i,j,k);
if(t==i)g(Xi);
else if(t==j)g(Xj);
else g(Xk);
return ;
}
}
//getMedian
Xi.clear();
Xj.clear();
Xk.clear();
for(auto &x:X)
{
if((rev[x][i]>rev[x][j] && rev[x][i]<rev[x][k]) || (rev[x][i]<rev[x][j] && rev[x][i]>rev[x][k]))Xi.push_back(x);
if((rev[x][j]>rev[x][i] && rev[x][j]<rev[x][k])||(rev[x][j]<rev[x][i] && rev[x][j]>rev[x][k]))Xj.push_back(x);
if((rev[x][k]>rev[x][i] && rev[x][k]<rev[x][j])||(rev[x][k]<rev[x][i] && rev[x][k]>rev[x][j]))Xk.push_back(x);
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))
{
int t=getMedian(i,j,k);
if(t==i)g(Xi);
else if(t==j)g(Xj);
else g(Xk);
return ;
}
}
//getLightest
Xi.clear();
Xj.clear();
Xk.clear();
for(auto &x:X)
{
if(rev[x][i]<rev[x][j] && rev[x][i]<rev[x][k])Xi.push_back(x);
if(rev[x][j]<rev[x][i] && rev[x][j]<rev[x][k])Xj.push_back(x);
if(rev[x][k]<rev[x][i] && rev[x][k]<rev[x][j])Xk.push_back(x);
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))
{
int t=getLightest(i,j,k);
if(t==i)g(Xi);
else if(t==j)g(Xj);
else g(Xk);
return ;
}
}
//getNextLightest
for(int l=1;l<=6;l++)
{
if(l!=i && l!=j && l!=k)
{
Xi.clear();
Xj.clear();
Xk.clear();
for(auto &x:X)
{
if(rev[x][l]>rev[x][i]&&rev[x][l]>rev[x][j]&&rev[x][l]>rev[x][k])
{
if(rev[x][i]<rev[x][j] && rev[x][i]<rev[x][k])Xi.push_back(x);
if(rev[x][j]<rev[x][i] && rev[x][j]<rev[x][k])Xj.push_back(x);
if(rev[x][k]<rev[x][i] && rev[x][k]<rev[x][j])Xk.push_back(x);
}
else
{
if(rev[x][l]<rev[x][i] && !(rev[x][l]<rev[x][j] && rev[x][j]<rev[x][i]) && !(rev[x][l]<rev[x][k] && rev[x][k]<rev[x][i]))Xi.push_back(x);
if(rev[x][l]<rev[x][j] && !(rev[x][l]<rev[x][i] && rev[x][i]<rev[x][j]) && !(rev[x][l]<rev[x][k] && rev[x][k]<rev[x][j]))Xj.push_back(x);
if(rev[x][l]<rev[x][k] && !(rev[x][l]<rev[x][i] && rev[x][i]<rev[x][k]) && !(rev[x][l]<rev[x][j] && rev[x][j]<rev[x][k]))Xk.push_back(x);
}
}
if(sz(Xi)<=u && sz(Xj)<=u && sz(Xk)<=u)
{
if(f(Xi) && f(Xj) && f(Xk))
{
int t=getNextLightest(i,j,k,l);
if(t==i)g(Xi);
else if(t==j)g(Xj);
else g(Xk);
return ;
}
}
}
}
}
}
}
puts("mang");
}
void orderCoins() {
vector<int>X;
for(int i=0;i<720;i++)X.push_back(i);
g(X);
int W[6];
for(int i=1;i<=6;i++)W[rev[ans][i]-1]=i;
answer(W);
}
Compilation message
scales.cpp: In function 'void init(int)':
scales.cpp:32:15: warning: unused parameter 'T' [-Wunused-parameter]
32 | void init(int T) {
| ~~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
340 KB |
Output is correct |
2 |
Correct |
220 ms |
320 KB |
Output is correct |
3 |
Correct |
222 ms |
340 KB |
Output is correct |
4 |
Correct |
219 ms |
340 KB |
Output is correct |
5 |
Correct |
222 ms |
336 KB |
Output is correct |
6 |
Correct |
226 ms |
340 KB |
Output is correct |
7 |
Correct |
220 ms |
212 KB |
Output is correct |
8 |
Correct |
218 ms |
340 KB |
Output is correct |
9 |
Correct |
226 ms |
340 KB |
Output is correct |
10 |
Correct |
222 ms |
340 KB |
Output is correct |
11 |
Correct |
224 ms |
212 KB |
Output is correct |
12 |
Correct |
223 ms |
340 KB |
Output is correct |
13 |
Correct |
224 ms |
340 KB |
Output is correct |
14 |
Correct |
222 ms |
340 KB |
Output is correct |
15 |
Correct |
222 ms |
332 KB |
Output is correct |
16 |
Correct |
224 ms |
344 KB |
Output is correct |
17 |
Correct |
222 ms |
328 KB |
Output is correct |
18 |
Correct |
220 ms |
344 KB |
Output is correct |
19 |
Correct |
227 ms |
320 KB |
Output is correct |
20 |
Correct |
223 ms |
320 KB |
Output is correct |
21 |
Correct |
228 ms |
320 KB |
Output is correct |
22 |
Correct |
224 ms |
340 KB |
Output is correct |
23 |
Correct |
223 ms |
340 KB |
Output is correct |
24 |
Correct |
224 ms |
320 KB |
Output is correct |
25 |
Correct |
220 ms |
340 KB |
Output is correct |
26 |
Correct |
223 ms |
340 KB |
Output is correct |
27 |
Correct |
225 ms |
320 KB |
Output is correct |
28 |
Correct |
225 ms |
280 KB |
Output is correct |
29 |
Correct |
225 ms |
340 KB |
Output is correct |
30 |
Correct |
231 ms |
340 KB |
Output is correct |
31 |
Correct |
222 ms |
320 KB |
Output is correct |
32 |
Correct |
220 ms |
340 KB |
Output is correct |
33 |
Correct |
225 ms |
320 KB |
Output is correct |
34 |
Correct |
218 ms |
340 KB |
Output is correct |
35 |
Correct |
224 ms |
332 KB |
Output is correct |
36 |
Correct |
221 ms |
340 KB |
Output is correct |
37 |
Correct |
215 ms |
212 KB |
Output is correct |
38 |
Correct |
221 ms |
340 KB |
Output is correct |
39 |
Correct |
233 ms |
340 KB |
Output is correct |
40 |
Correct |
221 ms |
324 KB |
Output is correct |