Submission #486313

# Submission time Handle Problem Language Result Execution time Memory
486313 2021-11-11T08:32:14 Z MilosMilutinovic Unscrambling a Messy Bug (IOI16_messy) C++14
100 / 100
3 ms 460 KB
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
 
/*
n=8
1000|0000
0100|0000
0010|0000
0001|0000
 
 
 
*/
 
int n;
VI ans;
 
void setup(int l,int r) {
	if (l>=r) return;
	string s=string(n,'1');
	rep(i,l,r+1) s[i]='0';
	int md=l+r>>1;
	rep(i,l,md+1) {
		s[i]='1';
		add_element(s);
		s[i]='0';
	}
	setup(l,md);
	setup(md+1,r);
}
 
void gao(int l,int r,VI v) {
	if (l==r) {
		//printf("::%d\n",SZ(v));
		ans[v[0]]=l;
		return;
	}
	string s=string(n,'1');
	rep(i,0,SZ(v)) s[v[i]]='0';
	int md=l+r>>1; VI left,right;
	rep(i,0,SZ(v)) {
		s[v[i]]='1';
		bool is=check_element(s);
		(is?left:right).pb(v[i]);
		s[v[i]]='0';
	}
	gao(l,md,left);
	gao(md+1,r,right);
}
 
VI restore_permutation(int N,int uselessW,int uselessR) {
	n=N;
	ans.resize(n);
	setup(0,n-1);
	compile_set();
	VI gas(n);
	iota(all(gas),0);
	gao(0,n-1,gas);
	return ans;
}

Compilation message

messy.cpp: In function 'void setup(int, int)':
messy.cpp:42:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |  int md=l+r>>1;
      |         ~^~
messy.cpp: In function 'void gao(int, int, VI)':
messy.cpp:60:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   60 |  int md=l+r>>1; VI left,right;
      |         ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n = 8
2 Correct 1 ms 300 KB n = 8
3 Correct 1 ms 292 KB n = 8
4 Correct 1 ms 204 KB n = 8
5 Correct 1 ms 204 KB n = 8
6 Correct 0 ms 204 KB n = 8
7 Correct 1 ms 204 KB n = 8
8 Correct 1 ms 296 KB n = 8
9 Correct 1 ms 204 KB n = 8
10 Correct 1 ms 204 KB n = 8
11 Correct 1 ms 204 KB n = 8
12 Correct 1 ms 296 KB n = 8
13 Correct 1 ms 204 KB n = 8
14 Correct 1 ms 204 KB n = 8
15 Correct 1 ms 292 KB n = 8
# Verdict Execution time Memory 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 292 KB n = 32
9 Correct 1 ms 204 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
# Verdict Execution time Memory 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 204 KB n = 32
10 Correct 1 ms 204 KB n = 32
11 Correct 1 ms 204 KB n = 32
12 Correct 1 ms 296 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB n = 128
2 Correct 2 ms 424 KB n = 128
3 Correct 2 ms 460 KB n = 128
4 Correct 1 ms 460 KB n = 128
5 Correct 3 ms 460 KB n = 128
6 Correct 3 ms 460 KB n = 128
7 Correct 2 ms 460 KB n = 128
8 Correct 1 ms 460 KB n = 128
9 Correct 2 ms 460 KB n = 128
10 Correct 2 ms 460 KB n = 128
11 Correct 2 ms 460 KB n = 128
12 Correct 2 ms 460 KB n = 128
13 Correct 2 ms 460 KB n = 128
14 Correct 2 ms 460 KB n = 128
15 Correct 2 ms 460 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB n = 128
2 Correct 2 ms 460 KB n = 128
3 Correct 2 ms 460 KB n = 128
4 Correct 2 ms 460 KB n = 128
5 Correct 1 ms 460 KB n = 128
6 Correct 2 ms 460 KB n = 128
7 Correct 2 ms 460 KB n = 128
8 Correct 1 ms 460 KB n = 128
9 Correct 1 ms 428 KB n = 128
10 Correct 1 ms 460 KB n = 128
11 Correct 2 ms 428 KB n = 128
12 Correct 2 ms 372 KB n = 128
13 Correct 1 ms 460 KB n = 128
14 Correct 2 ms 460 KB n = 128
15 Correct 2 ms 460 KB n = 128