# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388220 | AmineWeslati | Ancient Machine (JOI21_ancient_machine) | C++17 | 78 ms | 8960 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.
//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
#ifndef LOCAL
#include "Anna.h"
#endif
#ifdef LOCAL
int cnt=0;
void Send(int a){
cout << a << endl;
cnt++;
return;
}
#endif
void Anna(int N, V<char> S) {
map<char,int>mp;
mp['X']=0; mp['Y']=1; mp['Z']=2;
vi a;
FOR(i,0,N) a.pb(mp[S[i]]);
int fx=-1;
FOR(i,0,N){
if(a[i]==0){
if(fx==-1){
Send(1);
fx=i;
}
else Send(0);
}
else if(a[i]==2){
Send(0);
}
else{
if(fx==-1)
Send(0);
else{
int j=i+1;
while(j<N && a[j]!=2){
j++;
}
if(j==N){
FOR(j,i,N) Send(0);
}
else{
Send(1);
FOR(k,i+1,j) Send(0);
Send(1);
}
i=j;
}
}
}
}
#ifdef LOCAL
int main() {
boost; IO();
int N; cin>>N;
V<char>vec(N);
FOR(i,0,N) cin>>vec[i];
Anna(N,vec);
return 0;
}
#endif
//Change your approach
//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up
template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;
void IO() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////
#ifndef LOCAL
#include "Bruno.h"
#endif
#ifdef LOCAL
set<int>s;
vi a(MX);
int ans=0;
void Remove(int idx){
auto i=s.find(idx);
/*int y=(a[*i]==1);
if(i!=s.begin()){
i--;
if(a[*i]!=0) y=0;
i++;
i++;
if(i==s.end()) y=0;
else if(a[*i]!=2) y=0;
i--;
}
else y=0;
ans+=y;*/
s.erase(i);
cout << idx << endl;
}
#endif
vi rmvd(MX,0);
void rmv(int i){
rmvd[i]=1;
Remove(i);
}
void Bruno(int N, int L, vi a) {
assert(L==N);
int fx=-1;
vpi vec;
vi st;
FOR(i,0,N) if(a[i]==1) {
if(fx==-1){
fx=i;
continue;
}
st.pb(i);
if(sz(st)==2){
vec.eb(st[0],st[1]);
st.clear();
}
}
int lst=fx;
for(auto it: vec){
int l=it.fi,r=it.se;
FOR(i,lst+1,r) if(!a[i])
rmv(i);
rmv(l);
rmv(r);
lst=r;
}
FOR(i,0,N) if(!rmvd[i]) rmv(i);
}
#ifdef LOCAL
int main() {
boost; IO();
int N,L; cin>>N>>L;
FOR(i,0,N) s.insert(i);
vi a(L);
FOR(i,0,L) cin>>a[i];
Bruno(N,L,a);
return 0;
}
#endif
//Change your approach
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |