# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1141490 | brianhdzmdo | Coins (IOI17_coins) | C++20 | 0 ms | 0 KiB |
#include "coins.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <string>
#include <set>
#include <utility>
#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define ll long long
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, a, b) for (ll i = a - 1; i >= b; i--)
#define fi first
#define se second
#define mp(j, k) make_pair(j, k)
#define pb(x) push_back(x)
#define pbp(x, y) push_back({x, y})
#define in(x) insert(x)
#define vec vector<ll>
#define vecv vector<vector<ll> >
#define veb vector<bool>
#define vecp vector<pair<ll,ll>>
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define ac 1e-7
#define fauto(a) \
for (auto i : a) \
cout << i << " ";
#define fautop(a) \
for (auto i : a) \
cout << i.fi << " " << i.se << endl;
using namespace std;
vector<int> find_coin(vector<int>& b)
{
int one = 0, zero = 0;
int pos_o = -1, pos_z = -1;
fr(i, 0, 3)
{
if(b[i]){
one++;
pos_o = i;
}
else
{
zero++;
pos_z = i;
}
}
if(one == 1)
{
return pos_o;
}
else
return pos_z;
}
vector<int> coin_flips(vector<int>& b, int c)
{
vector<int> changes;
if(c == 1)
{
if(b[c] == b[c - 1] && b[c] == b[c + 1])
{
b[c] -= b[c] - 1;
changes.pb(c);
}
else if(b[c] == b[c -1] && b[c] != b[c + 1])
{
b[c - 1] -= b[c - 1] - 1;
changes.pb(c - 1);
}
else if(b[c] != b[c - 1] && b[c] == b[c + 1])
{
b[c + 1] -= b[c + 1] - 1;
changes.pb(c + 1);
}
}
else if(c == 0)
{
if(b[c] == b[c + 1] && b[c] == b[c + 2])
{
b[c] -= b[c] - 1;
changes.pb(c);
}
else if(b[c] == b[c + 1] && b[c] != b[c + 2])
{
b[c + 1] -= b[c + 1] - 1;
changes.pb(c + 1);
}
else if(b[c] != b[c + 1] && b[c] == b[c + 2])
{
b[c + 2] -= b[c + 2] - 1;
changes.pb(c + 2);
}
}
else if(c == 2)
{
if(b[c] == b[c - 1] && b[c] == b[c - 2])
{
b[c] -= b[c] - 1;
changes.pb(c);
}
else if(b[c] == b[c - 1] && b[c] != b[c - 2])
{
b[c - 1] -= b[c - 1] - 1;
changes.pb(c - 1);
}
else if(b[c] != b[c - 1] && b[c] == b[c - 2])
{
b[c - 2] -= b[c - 2] - 1;
changes.pb(c - 2);
}
}
return find_coin(changes);
}