# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017620 | AmirAli_H1 | Scales (IOI15_scales) | C++17 | 1 ms | 348 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.
// In the name of Allah
#include <bits/stdc++.h>
#include "scales.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mark[7];
vector<int> res, vc, vcx;
vector<int> adjr[7];
void init(int T) {
return ;
}
void opr(int M) {
if (M == 0) {
int j = len(vc);
int r = getLightest(vc[j - 1], vc[j - 2], vc[j - 3]);
for (int x : {vc[j - 1], vc[j - 2], vc[j - 3]}) {
if (x != r) adjr[x].pb(r);
}
vc.pop_back(); vc.pop_back(); vc.pop_back();
vc.pb(r);
}
else {
int r = getLightest(vc[0], vc[1], vc[2]);
for (int x : {vc[0], vc[1], vc[2]}) {
if (x != r) adjr[x].pb(r);
}
vcx.clear(); vcx.pb(r);
for (int i = 3; i < len(vc); i++) vcx.pb(vc[i]);
swap(vc, vcx);
}
}
int get_min() {
vc.clear();
for (int i = 1; i <= 6; i++) {
if (!mark[i]) {
bool ok = 1;
for (int j : adjr[i]) {
if (!mark[j]) {
ok = 0;
break;
}
}
if (ok) vc.pb(i);
}
}
int M = 0;
while (len(vc) >= 3) {
opr(M); M ^= 1;
}
if (len(vc) == 2) {
for (int i = 1; i <= 6; i++) {
if (!mark[i]) {
if (i != vc[0] && i != vc[1]) {
vc.pb(i);
break;
}
}
}
opr(M); M ^= 1;
}
return vc[0];
}
void orderCoins() {
fill(mark, mark + 7, 0); res.clear();
for (int i = 1; i <= 6; i++) adjr[i].clear();
for (int i = 0; i < 3; i++) {
int x = get_min();
mark[x] = 1; res.pb(x);
}
while (len(res) < 5) {
int x = res.back();
vc.clear();
for (int i = 1; i <= 6; i++) {
if (!mark[i]) vc.pb(i);
}
for (int i = 1; i <= 6; i++) {
if (len(vc) >= 3) break;
if (mark[i] && i != x) vc.pb(i);
}
int r = getNextLightest(vc[0], vc[1], vc[2], x);
mark[r] = 1; res.pb(r);
}
for (int i = 1; i <= 6; i++) {
if (!mark[i]) {
mark[i] = 1; res.pb(i);
}
}
int W[6];
for (int i = 0; i < 6; i++) W[i] = res[i];
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |