Please sign in first.
Submission #70233309
Source Code Expand
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int q, neg_count = 0;
scanf("%d", &q);
vector <int> vect;
vect.push_back(0);
for(int i = 1 ; i <= q ; i++)
{
int code;
scanf("%d", &code);
if(code == 1)
{
int temp = vect.back();
char x;
scanf("\n%c", &x);
if(x == '(')
temp++;
else
temp--;
vect.push_back(temp);
if(temp < 0)
neg_count++;
}
else
{
if(vect.back() < 0)
neg_count--;
vect.pop_back();
}
if(vect.back() == 0 && neg_count == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Brackets Stack Query |
| User | MichaelH |
| Language | C++ 17 (gcc 12.2) |
| Score | 300 |
| Code Size | 895 Byte |
| Status | AC |
| Exec Time | 87 ms |
| Memory | 7476 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:10:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
Main.cpp:17:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | scanf("%d", &code);
| ~~~~~^~~~~~~~~~~~~
Main.cpp:22:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("\n%c", &x);
| ~~~~~^~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| 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 | 3672 KiB |
| 01_small_00.txt | AC | 40 ms | 3500 KiB |
| 02_random_00.txt | AC | 71 ms | 3636 KiB |
| 02_random_01.txt | AC | 72 ms | 3504 KiB |
| 02_random_02.txt | AC | 71 ms | 3708 KiB |
| 02_random_03.txt | AC | 71 ms | 3588 KiB |
| 02_random_04.txt | AC | 71 ms | 3696 KiB |
| 02_random_05.txt | AC | 71 ms | 3700 KiB |
| 02_random_06.txt | AC | 71 ms | 3496 KiB |
| 02_random_07.txt | AC | 71 ms | 3888 KiB |
| 02_random_08.txt | AC | 75 ms | 3688 KiB |
| 02_random_09.txt | AC | 72 ms | 3688 KiB |
| 03_corner_00.txt | AC | 87 ms | 7416 KiB |
| 03_corner_01.txt | AC | 85 ms | 7424 KiB |
| 03_corner_02.txt | AC | 85 ms | 7428 KiB |
| 03_corner_03.txt | AC | 85 ms | 7476 KiB |
| 03_corner_04.txt | AC | 85 ms | 7416 KiB |
| 03_corner_05.txt | AC | 77 ms | 5336 KiB |