Submission #70226440


Source Code Expand

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef jlocal
#include<jdebug/debug.hpp>
#else
#define debug(...) 0;
#endif

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#if defined(__LP64__) || defined(_WIN64)
typedef __int128 lll;
#else
typedef long long lll;
#endif

#define pcount(x) __builtin_popcount(x)
#define pcountll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()

const ld pi = 3.14159265358979323846L;
const ld sqrt2 = 1.41421356237309504880L;

template<class T>
istream& operator>>(istream& in, vector<T> &a){
	for (int i = 0; i < a.size(); i ++)
		in >> a[i];
	return in;
}

template<class T>
ostream& operator<<(ostream& out, vector<T> &a){
	for (int i = 0; i < a.size(); i ++){
		if (i > 0) out << ' ';
		out << a[i];
	}
	return out;
}

#if defined(__LP64__) || defined(_WIN64)

istream& operator>>(istream& in, __int128 &x){
	string S;
	in >> S;
	for (char &y : S){
		x *= 10;
		x += (y - '0');
	}
	return in;
}

ostream& operator<<(ostream& out, __int128 &x){
	string s;
	while(x > 0){
		s.push_back((x % 10) + '0');
		x /= 10;
	}
	if (s.size() == 0)
		s.push_back('0');
	reverse(all(s));
	return out << s;
}

#endif

mt19937_64 MT64;
void pre_init() {
	MT64 = mt19937_64(chrono::system_clock::now().
	time_since_epoch().count());
}

void solve(int caso){
	int q;
	cin >> q;
	vector<int> conteo;
	vector<bool> negs;
	while(q --){
		int t;
		cin >> t;
		if (t == 1){
			char x; cin >> x;
			int v = (x == '(' ? 1 : -1);
			conteo.push_back(v + (conteo.empty() ? 0 : conteo.back()));
			negs.push_back((negs.empty() ? false : negs.back()) or conteo.back() < 0);
		}
		else{
			conteo.pop_back();
			negs.pop_back();
		}
		if (negs.empty() or (!negs.back() and conteo.back() == 0)){
			cout << "Yes\n";
		}
		else{
			cout << "No\n";
		}
	}
}

int main(){
#ifndef jlocal
	ios::sync_with_stdio(0); cin.tie(0);
#endif
	pre_init();

	int t = 1;
	for (int i = 1; i <= t; i ++){
		solve(i);
	}
	return 0;
}

Submission Info

Submission Time
Task C - Brackets Stack Query
User JOliva
Language C++ 20 (gcc 12.2)
Score 300
Code Size 2373 Byte
Status AC
Exec Time 49 ms
Memory 7500 KiB

Compile Error

Main.cpp: In function ‘void solve(int)’:
Main.cpp:82:16: warning: unused parameter ‘caso’ [-Wunused-parameter]
   82 | void solve(int caso){
      |            ~~~~^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 18
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 03_corner_00.txt, 03_corner_01.txt, 03_corner_02.txt, 03_corner_03.txt, 03_corner_04.txt, 03_corner_05.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3468 KiB
01_small_00.txt AC 25 ms 3456 KiB
02_random_00.txt AC 45 ms 3548 KiB
02_random_01.txt AC 45 ms 3484 KiB
02_random_02.txt AC 45 ms 3508 KiB
02_random_03.txt AC 45 ms 3352 KiB
02_random_04.txt AC 45 ms 3352 KiB
02_random_05.txt AC 45 ms 3636 KiB
02_random_06.txt AC 45 ms 3624 KiB
02_random_07.txt AC 45 ms 3504 KiB
02_random_08.txt AC 45 ms 3552 KiB
02_random_09.txt AC 45 ms 3408 KiB
03_corner_00.txt AC 49 ms 7300 KiB
03_corner_01.txt AC 47 ms 7376 KiB
03_corner_02.txt AC 48 ms 7500 KiB
03_corner_03.txt AC 48 ms 7396 KiB
03_corner_04.txt AC 47 ms 7340 KiB
03_corner_05.txt AC 43 ms 5256 KiB