이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#define F first
#define S second
//#define endl '\n'
//#define int long long
using namespace std;
void add_element(string x);
bool check_element(string x);
void compile_set();
vt<int> restore_permutation(int n, int w, int r)
{
{ // INIT
string s(n, '0'); s[0] = '1';
for(int i = 0; i < n; i++, s[i] = '1') add_element(s);
compile_set();
}
string cur(n, '0');
vt<int> ans(n, n - 1);
for(int ones = 1; ones < n; ones++)
{
srand(time(NULL));
string tmp = cur;
vt<int> used(n);
int used_cnt = ones - 1;
bool found = 0;
while(true)
{
if (used_cnt == n - 1) break;
int i = rand() % n;
if (tmp[i] == '1' || used[i]) continue;
tmp[i] = '1'; used[i] = 1;
if (check_element(tmp))
{
found = 1;
ans[i] = ones - 1;
break;
}
tmp[i] = '0';
used_cnt++;
}
if (!found)
{
for(int i = 0; i < n; i++)
{
if (tmp[i] == '1' || used[i]) continue;
tmp[i] = '1';
ans[i] = ones - 1;
break;
}
}
/*
for(int i = 0; i < n; i++)
{
if (tmp[i] == '1') continue;
tmp[i] = '1';
bool exist = check_element(tmp);
//cout << tmp << " " << exist << endl;
if (exist)
{
ans[i] = ones - 1;
break;
}
tmp[i] = '0';
}
*/
cur = tmp;
//cout << endl;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |