This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef GNORT
#include "cave.h"
#endif // GNORT
#include <bits/stdc++.h>
#define SQR(x) (1LL * ((x) * (x)))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(s) (int)s.size()
#define prev __prev
#define next __next
#define left __left
#define right __right
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;
using namespace std;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);
const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
template<class BUI, class TRONG>
bool minimize(BUI &x, const TRONG y){
if(x > y){
x = y;
return true;
} else return false;
}
template<class BUI, class TRONG>
bool maximize(BUI &x, const TRONG y){
if(x < y){
x = y;
return true;
} else return false;
}
/* Author : Bui Nguyen Duc Trong, Luong Van Chanh High School for the gifted*/
/* Template is copied by Trong */
/** Losing in Provincial Contests **/
/** TRYING HARDER**/
/** ORZ **/
/* -----------------[ MAIN CODE GOES HERE ]----------------- */
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#ifdef GNORT
//const int QUERY_LIMIT = 70000;
//
//struct Judger {
// int n;
// vector<int> perm, pos;
//
// int queryCount, answerCount;
//
// Judger() {
// queryCount = 0;
// n = 0;
// }
//
// void loadData(void) {
// cin >> n;
// perm.assign(n, 0);
// pos.assign(n, 0);
// for (int i = 0; i < n; i++) cin >> perm[i];
// for (int i = 0; i < n; i++) cin >> pos[i];
// queryCount = 0;
// answerCount = 0;
// }
//
// int tryCombination(int s[]) {
// printf("Try #%d:", queryCount + 1);
// for (int i = 0; i < n; i++) printf(" %d", s[i]);
// printf("\n");
//
// assert(++queryCount < QUERY_LIMIT);
// assert(answerCount == 0);
// for (int i = 0; i < n; i++) assert(s[i] == 0 || s[i] == 1);
//
// /// tinh ket qua
//
// int res = 0;
//
// printf("Returns: %d\n", res);
// return res;
// }
//
// void answer(int s[], int d[]) {
// assert(answerCount == 0);
// for (int i = 0; i < n; i++) if (s[i] != perm[i]) {
// printf("PERMUTATION WRONG ANSWER!\n");
//
// printf("Expected:");
// for (int j = 0; j < n; j++) printf(" %d", perm[j]);
// printf("\n");
//
// printf("Received:");
// for (int j = 0; j < n; j++) printf(" %d", s[j]);
// printf("\n");
//
// exit(EXIT_FAILURE);
// }
// for (int i = 0; i < n; i++) assert(d[i] == pos[i]);
// printf("CORRECT after %d queries\n", queryCount);
// }
//} judger;
//
//int tryCombination(int s[]) {
// return judger.tryCombination(s);
//}
//void answer(int s[], int d[]) {
// return judger.answer(s, d);
//}
//
//#endif // GNORT
#ifdef GNORT
struct Jury{
int n;
vector<int> state, door;
Jury() : n(0) {}
void init(){
cin >> n;
state.resize(n);
door.resize(n);
for(int i = 0; i < n; i++) cin >> state[i];
for(int i = 0; i < n; i++) cin >> door[i];
}
int tryCombination(int s[]){
int ans = -1;
for(int i = 0; i < n; i++) if(state[i] != s[i]){
if(ans == -1) ans = door[i];
else minimize(ans, door[i]);
}
cout << "Try:"; for(int i = 0; i < n; i++) cout << ' ' << s[i]; cout << '\n';
cout << "res: " << ans << '\n';
return ans;
}
void answer(int s[], int d[]){
bool wa = 0;
for(int i = 0; i < n; i++) wa |= (s[i] != state[i] || d[i] != door[i]);
cout << "Jury state:";
for(int x : state) cout << ' ' << x; cout << '\n';
cout << "Jury door:";
for(int x : door) cout << ' ' << x; cout << '\n';
cout << "Trong state:";
for(int i = 0; i < n; i++) cout << ' ' << s[i]; cout << '\n';
cout << "Trong door:";
for(int i = 0; i < n; i++) cout << ' ' << d[i]; cout << '\n';
cout << (wa ? "WA" : "AC") << '\n';
}
} jury;
int tryCombination(int s[]){
return jury.tryCombination(s);
}
void answer(int s[], int d[]){
jury.answer(s, d);
}
#endif // GNORT
bool quaduoc(int x, int y){
return y == -1 || x < y;
}
// dau tien tim 0 || 1
void exploreCave(int n){
vector<int> con(n), used(n, 0);
for(int i = 0; i < n; i++) con[i] = i;
int thu[n];
for(int i = 0; i < n; i++) thu[i] = 0;
int ans1[n], ans2[n];
for(int i = 0; i < n; i++){
for(int j : con) thu[j] = 0;
int c = quaduoc(i, tryCombination(thu)) ? 0 : 1;
int lo = 0, hi = sz(con) - 1, pos = -1;
while(lo <= hi){
int mid = (lo + hi) >> 1;
for(int j = 0; j <= mid; j++) thu[con[j]] = c;
for(int j = mid + 1; j < sz(con); j++) thu[con[j]] = c ^ 1;
if(quaduoc(i, tryCombination(thu))){
hi = mid - 1;
pos = mid;
} else lo = mid + 1;
}
thu[con[pos]] = c;
ans1[con[pos]] = c;
ans2[con[pos]] = i;
vector<int> tmp;
for(int j = 0; j < pos; j++) tmp.push_back(con[j]);
for(int j = pos + 1; j < sz(con); j++) tmp.push_back(con[j]);
con = tmp;
}
answer(ans1, ans2);
}
/*
4
1 1 1 0
3 1 0 2
door: 0 1 2 3
. 1 0 .
*/
#ifdef GNORT
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
const bool multitest = 0;
int tt = 1; if(multitest) cin >> tt;
while( tt-- ){
jury.init();
exploreCave(jury.n);
}
return 0;
}
#endif
# | 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... |