Submission #1002693
Source Code Expand
#include<cstdio> #include<algorithm> #include<cstring> #include<iostream> #include<vector> #include<set> #include<map> #include<bitset> #include<cmath> #include<string> #define ls (t<<1) #define rs ((t<<1)+1) #define mid ((l+r)>>1) #define fi first #define se second #define mk make_pair #define pb push_back #define N 1000005 #define M 200005 #define seed 23333 #define Mo 998244353 using namespace std; int i,j,m,n,p,k,ID[N],tot,Str[N],End[N],f[N],g[N],T[N]; int kong[N],vis[N],sum,full[N]; char c[N],title[N],s[N]; vector<pair<int,int> >ques[N]; void bl() { int i,ans=0,j,k,last; for (;;) { ++ans; last=n+1; for (i=n;i;--i) if (s[i]!=c[i]) { for (j=i;j;--j) if (c[j]==s[i]) break; if (!j) { puts("-1"); return; } for (k=j;k<=min(last,i);++k) c[k]=c[j]; last=j-1; } for (i=1;i<=n;++i) if (c[i]!=s[i]) break; if (i>n) break; } printf("%d\n",ans); } int main() { scanf("%d",&n); scanf("%s",c+1); scanf("%s",s+1); for (i=1;i<=n;++i) if (c[i]!=s[i]) break; if (i>n) { puts("0"); return 0; } for (i=1;i<=n;i=j) { ++tot; for (j=i;s[j]==s[i]&&j<=n;++j); title[tot]=s[i]; Str[tot]=i; End[tot]=j-1; } int now=n,ans=0; for (i=tot;i;--i) { while (now&&(now>Str[i]||c[now]!=title[i])) --now; if (!now) { puts("-1"); return 0; } ID[i]=now; vis[now]=1; } f[tot]=(ID[tot]!=Str[tot]); g[tot]=1; now=tot; for (i=n;i;--i) if (!vis[i]) full[i]=full[i+1]; else { full[i]=full[i+1]+1; if (now!=tot) { int needgo=full[i+1]-full[Str[now]+1]; if (needgo==0) f[now]=(ID[now]!=Str[now]); else ques[Str[now]+1].pb(mk(needgo,now)); } --now; } for (i=n;i;--i) { if (!vis[i]) { ++sum; kong[1-sum+n]=i; } for (j=0;j<(int)ques[i].size();++j) T[ques[i][j].se]=kong[ques[i][j].fi-sum+n]; } now=tot; for (i=n;i;--i) if (vis[i]) { if (now!=tot) { int needgo=full[i+1]-full[Str[now]+1]; if (needgo==0) f[now]=(ID[now]!=Str[now]); else { int pos=T[now]; f[now]=full[i+1]-full[pos]+1; } if (f[now]==1&&f[now+1]==0) g[now]=1; else g[now]=max(f[now]+(Str[now]!=End[now]),f[now+1]+1); } --now; } for (i=1;i<=tot;++i) ans=max(ans,g[i]); printf("%d\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | F - Shik and Copying String |
User | qiaoranliqu |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 2510 Byte |
Status | AC |
Exec Time | 153 ms |
Memory | 89088 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:56:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:57:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",c+1); ^ ./Main.cpp:58:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s+1); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 27 ms | 23680 KB |
001.txt | AC | 28 ms | 23680 KB |
002.txt | AC | 27 ms | 23680 KB |
003.txt | AC | 27 ms | 23680 KB |
004.txt | AC | 27 ms | 23680 KB |
005.txt | AC | 27 ms | 23680 KB |
006.txt | AC | 27 ms | 23680 KB |
007.txt | AC | 27 ms | 23680 KB |
008.txt | AC | 28 ms | 23680 KB |
009.txt | AC | 28 ms | 23680 KB |
010.txt | AC | 28 ms | 23808 KB |
011.txt | AC | 28 ms | 23808 KB |
012.txt | AC | 27 ms | 23808 KB |
013.txt | AC | 27 ms | 23808 KB |
014.txt | AC | 27 ms | 23808 KB |
015.txt | AC | 28 ms | 23808 KB |
016.txt | AC | 28 ms | 23808 KB |
017.txt | AC | 28 ms | 23808 KB |
018.txt | AC | 28 ms | 23808 KB |
019.txt | AC | 28 ms | 23808 KB |
020.txt | AC | 28 ms | 23808 KB |
021.txt | AC | 28 ms | 23808 KB |
022.txt | AC | 28 ms | 23808 KB |
023.txt | AC | 28 ms | 23680 KB |
024.txt | AC | 28 ms | 23808 KB |
025.txt | AC | 35 ms | 25600 KB |
026.txt | AC | 151 ms | 89088 KB |
027.txt | AC | 102 ms | 61312 KB |
028.txt | AC | 140 ms | 69504 KB |
029.txt | AC | 139 ms | 70144 KB |
030.txt | AC | 63 ms | 39680 KB |
031.txt | AC | 63 ms | 39808 KB |
032.txt | AC | 64 ms | 39936 KB |
033.txt | AC | 64 ms | 40064 KB |
034.txt | AC | 65 ms | 40192 KB |
035.txt | AC | 65 ms | 40192 KB |
036.txt | AC | 65 ms | 39936 KB |
037.txt | AC | 64 ms | 39808 KB |
038.txt | AC | 63 ms | 39296 KB |
039.txt | AC | 62 ms | 38912 KB |
040.txt | AC | 117 ms | 61696 KB |
041.txt | AC | 133 ms | 73088 KB |
042.txt | AC | 149 ms | 85888 KB |
043.txt | AC | 150 ms | 87424 KB |
044.txt | AC | 153 ms | 88832 KB |
045.txt | AC | 152 ms | 88960 KB |
046.txt | AC | 151 ms | 89088 KB |
047.txt | AC | 151 ms | 89088 KB |
048.txt | AC | 151 ms | 89088 KB |
049.txt | AC | 152 ms | 89088 KB |
050.txt | AC | 55 ms | 42240 KB |
051.txt | AC | 56 ms | 42240 KB |
052.txt | AC | 51 ms | 38272 KB |
053.txt | AC | 113 ms | 63232 KB |
054.txt | AC | 112 ms | 63232 KB |
055.txt | AC | 111 ms | 62592 KB |
056.txt | AC | 114 ms | 62336 KB |
057.txt | AC | 112 ms | 62336 KB |
058.txt | AC | 112 ms | 62336 KB |
example0.txt | AC | 28 ms | 23680 KB |
example1.txt | AC | 27 ms | 23680 KB |
example2.txt | AC | 28 ms | 23680 KB |
example3.txt | AC | 27 ms | 23680 KB |