#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#pragma GCC optimize ("Ofast")
#define double ld
const int inf = 2e9;
const int INF = 4e18;
const int mod = 1e9+7;
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int, int>
#define vpi vector<pi>
#define vb vector<bool>
#define vvb vector<vb>
#define pb push_back
#define read(a) for(auto &x:a) cin >> x;
#define print(a) for(auto x:a) cout << x << " "; cout << "\n";
#define rs resize
#define as assign
#define vc vector<char>
#define vvc vector<vc>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ppb pop_back
#define MP make_pair
// #define int ll
void add_element(string x);
void compile_set();
bool check_element(string x);
int* restore_permutation(int n, int w, int r){
int p[n];
function<void(int, int)> add = [&](int l, int r){
if(l == r) return;
for(int j=l; j<l+(r-l+1)/2; j++){
string s;
for(int i=0; i<n; i++)
if(i < l || i > r || i == j) s += '1';
else s += '0';
add_element(s);
}
add(l, l+(r-l+1)/2-1);
add(l+(r-l+1)/2, r);
};
add(0, n-1);
compile_set();
function<void(int, int, vi)> solve = [&](int l, int r, vi v){
if(l == r){
p[n-1-l] = n-1-v[0];
return;
}
vi a, b;
for(auto &x:v){
string s;
for(int i=0; i<n; i++){
if(i != x && binary_search(all(v), i)) s += '0';
else s += '1';
}
if(check_element(s)) a.pb(x);
else b.pb(x);
}
solve(l, l+(r-l+1)/2-1, a);
solve(l+(r-l+1)/2, r, b);
};
vi v; iota(all(v), 0);
solve(0, n-1, v);
return p;
}
/*stolen stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* READ CONSTRAINTS
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message
messy.cpp:9:17: warning: overflow in conversion from 'double' to 'int' changes value from '4.0e+18' to '2147483647' [-Woverflow]
9 | const int INF = 4e18;
| ^~~~
messy.cpp: In function 'int* restore_permutation(int, int, int)':
messy.cpp:80:12: warning: address of local variable 'p' returned [-Wreturn-local-addr]
80 | return p;
| ^
messy.cpp:39:9: note: declared here
39 | int p[n];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
197 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
205 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
198 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
461 ms |
323316 KB |
grader returned WA |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
189 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |