# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
875923 | danikoynov | Broken Device 2 (JOI22_device2) | 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 "Bruno.h"
#include <utility>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long Bruno(std::vector<int> u)
{
ll ans = 0, last = 0, bit = 0;
ll pref = 0;
/**for (int cur : u)
cout << cur << " ";
cout << endl;*/
for (int i = 0; i < u.size(); i ++)
{
ll val = pref + u[i];
pref += u[i];
val = val - (i + 1 - val);
ll ost = val % 3;
if (ost < 0)
ost += 3;
///cout << pref << " : " << val << " " << val % 3 << endl;
if (ost <= 1)
{
val -= ost;
if (last == -1e9)
last = val / 3;
else
if (val / 3 > last)
{
last = val / 3;
ans = ans + ((ll)(1) << bit);
bit ++;
}
else
if (val / 3 < last)
{
last = val / 3;
bit ++;
}
}
}
//cout << endl;
//cout << ans << endl;
return ans;
}