답안 #388207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388207 2021-04-10T14:12:50 Z AmineWeslati Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
93 ms 9536 KB
//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
void Send(int a){
	return; 
}
#endif

void Anna(int N, V<char> S) {
	FOR(i,0,N){
		if(S[i]=='X') Send(0),Send(0); 
		else if(S[i]=='Y') Send(0),Send(1);
		else Send(1),Send(0);
	}
}

#ifdef LOCAL
int main() {
    boost; IO();
    

    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);
}
#endif

void rmv(int i){
	Remove(i);
}

void Bruno(int N, int L, vi A) {
	vi vec;
	for(int i=0; i<L; i+=2){
		vec.pb(A[i]*2+A[i+1]);
	}

	vi st; 
	FOR(i,0,N){
		if(vec[i]==0){
			st.pb(i);
		}
		else if(vec[i]==2){
			rmv(i);
		}
		else{
			if(!sz(st)) 
				rmv(i);
			else{
				int j=i+1; 
				while(j<N && vec[j]!=2){
					rmv(j);
					j++;
				}
				rmv(i);
				i=j-1; 
			}
		}
	}
	while(sz(st)){
		rmv(st.back());
		st.pop_back();
	}
}



#ifdef LOCAL
int main() {
    boost; IO();

    int N; cin>>N;
    FOR(i,0,N) s.insert(i);
    vi vec;
    FOR(i,0,N){
    	int x; cin>>x; 
    	int y; cin>>y; 
    	vec.pb(x);
    	vec.pb(y);
    	a[i]=x*2+y;
    }
    Bruno(N,sz(vec),vec);
    cout << ans << endl;
    

    return 0;
}
#endif
//Change your approach 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Incorrect 2 ms 492 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 9536 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -