Submission #996290

#TimeUsernameProblemLanguageResultExecution timeMemory
996290mindiyakCave (IOI13_cave)C++14
100 / 100
1271 ms2068 KiB
#include "cave.h" #include <bits/stdc++.h> #include <string> #include <iostream> #include <cmath> #include <numeric> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<int, int> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<ld> vd; typedef vector<long> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define uid(a, b) uniform_int_distribution<int>(a, b)(rng) #define len(x) (int)(x).size() #define mp make_pair #define pb push_back #define F first #define nl endl #define S second #define lb lower_bound #define ub upper_bound #define aint(x) x.begin(), x.end() #define raint(x) x.rbegin(), x.rend() #define ins insert const int MOD = 1000000007; vi solved; int n; int tryCombination2(vi arr){ int arr2[n]; FOR(i,0,n)arr2[i] = arr[i]; return tryCombination(arr2); } int binarySearch(int left,int right,int activeType,int length){ if(left == right){ // cout << "end - " << left << endl; return left; } int mid = (left+right)/2; vi temp = solved; FOR(i,0,n){ if(temp[i] == -1){ if(i<=mid and i>=left) temp[i] = activeType; else temp[i] = (activeType+1)%2; } } // cout << left << " " << right << " " << mid << " " << activeType << " | "; // for(auto i:temp)cout << i << " "; // cout << " | " << tryCombination2(temp) << endl; int val = tryCombination2(temp); if(val > length || val == -1){ return binarySearch(left,mid,activeType,length); }else{ return binarySearch(mid+1,right,activeType,length); } } int tryActive(int length){ vi temp = solved; FOR(i,0,n){ if(temp[i] == -1)temp[i] = 1; } int val = tryCombination2(temp); return ((val > length) || (val == -1)); } void exploreCave(int N) { n = N; solved = vi(N,-1); int doornum[N],active[N]; FOR(i,0,N){ // cout << i << endl; int activeType = tryActive(i); int pos = binarySearch(0,n,activeType,i); solved[pos] = activeType; doornum[pos] = i; active[pos] = activeType; // cout << endl; } answer(active,doornum); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...