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;
typedef long long ll;
ll INF = 1e18+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "doll.h"
void create_circuit(int M, std::vector<int> A) {
int n = A.size();
vector<int> C(M + 1);
f(i,0,M+1){
C[i] = 0;
}
C[0] = A[0];
ll pos = -1;
vector<int> X, Y;
vll mp[M+5];
set<ll>ex;
A.pb(0);
f(i,0,n){
mp[A[i]].pb(A[i+1]);
}
set<ll>ev;
f(i,1,n+1){
if(ev.count(A[i-1])){
continue;
}
ev.insert(A[i-1]);
if(mp[A[i-1]].size() == 1){
C[A[i-1]] = A[i];
}
else if(mp[A[i-1]].size() == 2){
C[A[i-1]] = pos;
pos--;
X.pb(mp[A[i-1]][0]);
Y.pb(mp[A[i-1]][1]);
}
else if(mp[A[i-1]].size() == 3){
C[A[i-1]] = pos;
pos--;
X.pb(pos);
pos--;
Y.pb(pos);
pos--;
X.pb(mp[A[i-1]][0]);
Y.pb(mp[A[i-1]][2]);
X.pb(mp[A[i-1]][1]);
Y.pb(mp[A[i-1]][2]);
}
else{
C[A[i-1]] = pos;
pos--;
X.pb(pos);
pos--;
Y.pb(pos);
pos--;
X.pb(mp[A[i-1]][0]);
Y.pb(mp[A[i-1]][2]);
X.pb(mp[A[i-1]][1]);
Y.pb(mp[A[i-1]][3]);
}
}
assert(X.size() <= n);
answer(C, X, Y);
}
Compilation message (stderr)
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from doll.cpp:1:
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:81:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
81 | assert(X.size() <= n);
| ~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |