Submission #48568908


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
#define N 200001
bool flag[N];
int n,opt[N],a[N],num[N],now,ans;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d%d",opt+i,a+i);
for(int i=n;i>=1;--i){
if(opt[i]==2)++num[a[i]];
else if(num[a[i]]){
--num[a[i]];flag[i]=1;
}
}
for(int i=1;i<=n;++i){
if(num[i]!=0){
puts("-1");return 0;
}
}
for(int i=1;i<=n;++i){
if(flag[i])++now;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>
using namespace std;
#define N 200001
bool flag[N];
int n,opt[N],a[N],num[N],now,ans;
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;++i)scanf("%d%d",opt+i,a+i);
  for(int i=n;i>=1;--i){
    if(opt[i]==2)++num[a[i]];
    else if(num[a[i]]){
      --num[a[i]];flag[i]=1;
    }
  }
  for(int i=1;i<=n;++i){
    if(num[i]!=0){
      puts("-1");return 0;
    }
  }
  for(int i=1;i<=n;++i){
    if(flag[i])++now;
    if(opt[i]==2)--now;
    ans=max(ans,now);
  }
  printf("%d\n",ans);
  for(int i=1;i<=n;++i){
    if(opt[i]==1)printf("%d ",flag[i]);
  }
  return 0;
}

Submission Info

Submission Time
Task E - Takahashi Quest
User linguosheng
Language C++ 20 (gcc 12.2)
Score 450
Code Size 619 Byte
Status AC
Exec Time 33 ms
Memory 6352 KB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:7:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |   scanf("%d",&n);
      |   ~~~~~^~~~~~~~~
Main.cpp:8:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   for(int i=1;i<=n;++i)scanf("%d%d",opt+i,a+i);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 47
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 02_handmade_39.txt, 02_handmade_40.txt, 02_handmade_41.txt, 02_handmade_42.txt, 02_handmade_43.txt, 02_handmade_44.txt, 02_handmade_45.txt, 02_handmade_46.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3824 KB
00_sample_01.txt AC 1 ms 3656 KB
00_sample_02.txt AC 1 ms 3632 KB
01_random_03.txt AC 3 ms 3904 KB
01_random_04.txt AC 7 ms 4424 KB
01_random_05.txt AC 25 ms 5560 KB
01_random_06.txt AC 26 ms 5748 KB
01_random_07.txt AC 3 ms 3840 KB
01_random_08.txt AC 8 ms 4520 KB
01_random_09.txt AC 14 ms 5088 KB
01_random_10.txt AC 5 ms 4196 KB
01_random_11.txt AC 20 ms 5792 KB
01_random_12.txt AC 7 ms 4180 KB
01_random_13.txt AC 20 ms 5712 KB
01_random_14.txt AC 8 ms 4444 KB
01_random_15.txt AC 23 ms 5628 KB
01_random_16.txt AC 13 ms 4880 KB
01_random_17.txt AC 6 ms 4040 KB
01_random_18.txt AC 14 ms 4724 KB
01_random_19.txt AC 19 ms 5548 KB
01_random_20.txt AC 2 ms 3864 KB
01_random_21.txt AC 32 ms 6292 KB
01_random_22.txt AC 32 ms 6296 KB
01_random_23.txt AC 33 ms 6220 KB
01_random_24.txt AC 25 ms 6232 KB
01_random_25.txt AC 26 ms 6228 KB
01_random_26.txt AC 25 ms 6196 KB
01_random_27.txt AC 30 ms 6160 KB
01_random_28.txt AC 30 ms 6164 KB
01_random_29.txt AC 31 ms 6352 KB
01_random_30.txt AC 25 ms 5456 KB
01_random_31.txt AC 19 ms 5332 KB
01_random_32.txt AC 24 ms 5576 KB
01_random_33.txt AC 32 ms 5448 KB
01_random_34.txt AC 24 ms 5868 KB
01_random_35.txt AC 29 ms 6352 KB
01_random_36.txt AC 19 ms 4844 KB
01_random_37.txt AC 19 ms 5188 KB
01_random_38.txt AC 27 ms 5448 KB
02_handmade_39.txt AC 29 ms 6072 KB
02_handmade_40.txt AC 29 ms 6028 KB
02_handmade_41.txt AC 30 ms 5980 KB
02_handmade_42.txt AC 23 ms 6352 KB
02_handmade_43.txt AC 23 ms 6352 KB
02_handmade_44.txt AC 25 ms 6352 KB
02_handmade_45.txt AC 1 ms 3768 KB
02_handmade_46.txt AC 1 ms 3584 KB


2025-02-27 (Thu)
22:43:46 +00:00