Submission #1038319

# Submission time Handle Problem Language Result Execution time Memory
1038319 2024-07-29T16:30:16 Z Alihan_8 Unscrambling a Messy Bug (IOI16_messy) C++17
100 / 100
2 ms 856 KB
#include <vector>

#include "messy.h"

#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

std::vector<int> restore_permutation(int n, int w, int r) {
	int b = __lg(n);
	
	for ( int i = b; i > 0; i-- ){
		int k = 1 << i;
		
		for ( int j = 0; j < n; j += k ){
			string s = string(n, '0');
			
			for ( int t = j; t < j + k; t++ ){
				s[t] = '1';
			}
			
			for ( int t = j; t < j + k / 2; t++ ){
				s[t] = '0';
				
				add_element(s);
				
				s[t] = '1';
			}
		}
	}
	
	compile_set();
	
	vector <int> ans(n);
	
	auto dfs = [&](auto dfs, int l, int r, auto p) -> void{
		if ( l == r ){
			ans[p[0]] = l;
			
			return;
		}
		
		string s = string(n, '0');
		
		for ( auto &x: p ){
			s[x] = '1';
		}
		
		vector <int> L, R;
		
		for ( auto &x: p ){
			s[x] = '0';
			
			if ( check_element(s) ){
				L.pb(x);
			} else R.pb(x);
			
			s[x] = '1';
		}
		
		int m = (l + r) / 2;
		
		dfs(dfs, l, m, L), dfs(dfs, m + 1, r, R);
	};
	
	vector <int> p(n);
	
	iota(all(p), 0);
	
	dfs(dfs, 0, n - 1, p);
	
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB n = 8
2 Correct 0 ms 348 KB n = 8
3 Correct 0 ms 348 KB n = 8
4 Correct 0 ms 348 KB n = 8
5 Correct 0 ms 344 KB n = 8
6 Correct 0 ms 348 KB n = 8
7 Correct 0 ms 348 KB n = 8
8 Correct 0 ms 348 KB n = 8
9 Correct 0 ms 348 KB n = 8
10 Correct 0 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 348 KB n = 8
13 Correct 1 ms 600 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 1 ms 604 KB n = 8
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 1 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 0 ms 344 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 0 ms 348 KB n = 32
8 Correct 0 ms 348 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 0 ms 348 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 0 ms 348 KB n = 32
15 Correct 0 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n = 32
2 Correct 0 ms 348 KB n = 32
3 Correct 1 ms 348 KB n = 32
4 Correct 0 ms 348 KB n = 32
5 Correct 0 ms 348 KB n = 32
6 Correct 0 ms 348 KB n = 32
7 Correct 0 ms 348 KB n = 32
8 Correct 0 ms 344 KB n = 32
9 Correct 0 ms 348 KB n = 32
10 Correct 0 ms 348 KB n = 32
11 Correct 0 ms 348 KB n = 32
12 Correct 0 ms 348 KB n = 32
13 Correct 0 ms 348 KB n = 32
14 Correct 0 ms 348 KB n = 32
15 Correct 1 ms 348 KB n = 32
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 1 ms 604 KB n = 128
4 Correct 1 ms 604 KB n = 128
5 Correct 1 ms 604 KB n = 128
6 Correct 2 ms 604 KB n = 128
7 Correct 1 ms 604 KB n = 128
8 Correct 1 ms 600 KB n = 128
9 Correct 1 ms 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 1 ms 600 KB n = 128
12 Correct 1 ms 604 KB n = 128
13 Correct 1 ms 436 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 604 KB n = 128
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB n = 128
2 Correct 1 ms 604 KB n = 128
3 Correct 1 ms 604 KB n = 128
4 Correct 1 ms 604 KB n = 128
5 Correct 1 ms 440 KB n = 128
6 Correct 1 ms 436 KB n = 128
7 Correct 1 ms 600 KB n = 128
8 Correct 1 ms 604 KB n = 128
9 Correct 1 ms 604 KB n = 128
10 Correct 1 ms 604 KB n = 128
11 Correct 1 ms 604 KB n = 128
12 Correct 1 ms 856 KB n = 128
13 Correct 1 ms 604 KB n = 128
14 Correct 1 ms 604 KB n = 128
15 Correct 1 ms 628 KB n = 128