# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44521 | MatheusLealV | Coins (IOI17_coins) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int> coin_flips(vector<int> a, int x)
{
int ini = 0, fim = 63, mid;
set<int> forb, usados;
vector<int> trocados;
for(int k = 0; k < 8; k++)
{
mid = (ini + fim)/2;
if( x >= mid)
{
if(!a[mid]) usados.insert(mid);
a[mid] = 1;
ini = mid + 1;
forb.insert(mid);
}
else
{
if(a[mid]) usados.insert(mid);
a[mid] = 0;
fim = mid - 1;
forb.insert(mid);
}
}
for(auto x: usados) trocados.push_back(x);
if( trocados.size() == 0)
{
for(int p = 0; p < 64; p++)
if(!forb.count(p)) trocados.push_back(p);
}
return trocados;
}
int find_coin(vector<int> a)
{
int ini = 0, fim = 63, mid;
for(int k = 0; k < 20; k++)
{
mid = (ini + fim)/2;
if(a[mid]) ini = mid + 1;
else fim = mid - 1;
}
return mid;
}
char x;
int main()
{
int k, T, KI;
cin>>T>>KI;
while(T --)
{
cin>>k;
for(int i = 0; i < 64; i++) cin>>x, v.push_back(x);
vector<int> vi = coin_flips(v, k);
cout<<find_coin(vi)<<"\n";
v.clear();
}
}