写的比较爽的一道小模拟。
交了 \(5\) 发之后才过,码力有待加强。
题意不说了。
第一版代码(73pts):
此代码样例没过,仅是想看看当前代码的得分。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid (l+r)>>1
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
ll t;
ll n;
string s,ss[110][5];
void solve()
{
map<string,ll>mp;
stack<string>q;
stack<ll>times;
cin>>n>>s;
ll sum=0,pd=0,ans=0,S=0;
forl(i,1,n)
{
cin>>ss[i][1];
if(ss[i][1]=="E" && sum && !pd)
{
string st=q.top();
mp[st]--;
q.pop();
sum--;
S-=times.top();
times.pop();
}
else if(ss[i][1]=="E")
pd=1;
else
{
sum++;
ll num1=0,num2=0;
forl(j,2,4)
{
cin>>ss[i][j];
if(pd)
continue;
if(j==2)
{
q.push(ss[i][j]);
mp[ss[i][j]]++;
if(mp[ss[i][j]]>1)
pd=1;
}
if(j==3)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
num1=100;
else
num1=1e18;
}
if(j==4)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
num2=100;
else
num2=1e18;
if(num2-num1>1e17)
times.push(1),S++,ans=max(ans,S);
else
times.push(0);
}
}
}
}
if(pd || sum)
cout<<"ERR\n";
else
{
string nums="",last="";
if(ans==0)
last="O(1)";
else
{
while(ans)
nums+=ans%10+'0',ans/=10;
reverse(nums.begin(),nums.end());
last="O(n^"+nums+")";
}
if(last==s)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
int main()
{
IOS;
t=1;
cin>>t;
while(t--)
solve();
/******************/
/*while(L<q[i].l) */
/* del(a[L++]);*/
/*while(L>q[i].l) */
/* add(a[--L]);*/
/*while(R<q[i].r) */
/* add(a[++R]);*/
/*while(R>q[i].r) */
/* del(a[R--]);*/
/******************/
QwQ;
}
此代码 hack 数据:
in:
8
2 O(1)
F i 1 1
E
2 O(n^1)
F x 1 n
E
1 O(1)
F x 1 n
4 O(n^2)
F x 5 n
F y 10 n
E
E
4 O(n^2)
F x 9 n
E
F y 2 n
E
4 O(n^1)
F x 9 n
F y n 4
E
E
4 O(1)
F y n 4
F x 9 n
E
E
4 O(n^2)
F x 1 n
F x 1 10
E
E
out:
Yes
Yes
ERR
Yes
No
Yes
Yes
ERR
第二版代码(37pts)。
样例过了,然后提交。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid (l+r)>>1
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
ll t;
ll n;
string s,ss[110][5];
void solve()
{
map<string,ll>mp;
stack<string>q;
stack<ll>times;
cin>>n>>s;
ll sum=0,pd=0,ans=0,S=0;
forl(i,1,n)
{
cin>>ss[i][1];
if(ss[i][1]=="E" && sum && !q.empty() && !times.empty() && !pd)
{
string st=q.top();
mp[st]--;
q.pop();
sum--;
S-=times.top();
times.pop();
}
else if(ss[i][1]=="E")
pd=1;
else
{
sum++;
ll num1=0,num2=0;
forl(j,2,4)
{
cin>>ss[i][j];
if(pd)
continue;
if(j==2)
{
q.push(ss[i][j]);
mp[ss[i][j]]++;
if(mp[ss[i][j]]>1)
pd=1;
}
if(j==3)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
num1=100;
else
num1=1e18;
}
if(j==4)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
num2=100;
else
num2=1e18;
if(num2-num1>1e17)
{
if(times.empty())
times.push(1),S++,ans=max(ans,S);
else
{
if(times.top()==1)
times.push(1),S++,ans=max(ans,S);
else
times.push(0);
}
}
else
times.push(0);
ans=max(ans,S);
}
}
}
}
if(pd || sum)
cout<<"ERR\n";
else
{
string nums="",last="";
if(ans==0)
last="O(1)";
else
{
while(ans)
nums+=ans%10+'0',ans/=10;
reverse(nums.begin(),nums.end());
last="O(n^"+nums+")";
}
if(last==s)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
int main()
{
IOS;
t=1;
cin>>t;
while(t--)
solve();
/******************/
/*while(L<q[i].l) */
/* del(a[L++]);*/
/*while(L>q[i].l) */
/* add(a[--L]);*/
/*while(R<q[i].r) */
/* add(a[++R]);*/
/*while(R>q[i].r) */
/* del(a[R--]);*/
/******************/
QwQ;
}
此代码 hack 数据:
in:
2
8 O(n^2)
F a 57 n
F b 69 92
F c 85 87
F d 38 n
E
E
E
E
2 O(n^1)
F a 27 n
E
out:
Yes
Yes
第三版代码(73pts):
过了样例与前两个 hack 数据。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid (l+r)>>1
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
ll t;
ll n;
string s,ss[110][5];
void solve()
{
map<string,ll>mp;
stack<string>q;
stack<ll>times;
cin>>n>>s;
ll sum=0,pd=0,ans=0,S=0;
forl(i,1,n)
{
cin>>ss[i][1];
if(ss[i][1]=="E" && sum && !q.empty() && !times.empty() && !pd)
{
string st=q.top();
mp[st]--;
q.pop();
sum--;
ll timetop=times.top();
if(timetop==1)
S--;
// S-=times.top();
times.pop();
}
else if(ss[i][1]=="E")
pd=1;
else
{
sum++;
ll num1=0,num2=0;
forl(j,2,4)
{
cin>>ss[i][j];
if(pd)
continue;
if(j==2)
{
q.push(ss[i][j]);
mp[ss[i][j]]++;
if(mp[ss[i][j]]>1)
pd=1;
}
if(j==3)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
num1=100;
else
num1=1e18;
}
if(j==4)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
num2=100;
else
num2=1e18;
if(num2-num1>1e17)
{
if(times.empty())
times.push(1),S++,ans=max(ans,S);
else
{
if(times.top()==1 || times.top()==-1)
times.push(1),S++,ans=max(ans,S);
else
times.push(0);
}
}
else
times.push(-1);
ans=max(ans,S);
}
}
}
}
if(pd || sum)
cout<<"ERR\n";
else
{
string nums="",last="";
if(ans==0)
last="O(1)";
else
{
while(ans)
nums+=ans%10+'0',ans/=10;
reverse(nums.begin(),nums.end());
last="O(n^"+nums+")";
}
if(last==s)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
int main()
{
IOS;
t=1;
cin>>t;
while(t--)
solve();
/******************/
/*while(L<q[i].l) */
/* del(a[L++]);*/
/*while(L>q[i].l) */
/* add(a[--L]);*/
/*while(R<q[i].r) */
/* add(a[++R]);*/
/*while(R>q[i].r) */
/* del(a[R--]);*/
/******************/
QwQ;
}
此代码 hack 数据:
in:
2
54 O(n^9)
F a 8 n
F b 60 62
F c 20 n
F d 81 n
F e 70 n
F f 78 n
E
E
E
E
E
E
F a 76 n
F b 34 n
F c 16 n
F d 2 n
F e 5 n
F f 87 n
F g 8 n
F h 3 n
F i n 17
E
E
E
E
E
E
E
E
E
F a 90 n
F b 79 n
F c 24 n
F d 58 n
F e 58 n
F f 61 32
F g 5 n
F h 80 n
F i 54 n
F j 5 n
F k 79 97
F l 61 86
E
E
E
E
E
E
E
E
E
E
E
E
42 O(n^4)
F a 38 n
F b 7 n
F c n n
F d 79 n
F e 20 n
F f 99 7
F g 68 n
F h 74 n
F i 24 n
E
E
E
E
E
E
E
E
E
F a 10 n
F b 65 n
F c 45 91
F d n 7
F e 44 n
E
E
E
E
E
F a 75 n
F b 55 n
F c 82 39
F d 59 n
F e 38 n
F f 36 50
F g 40 n
E
E
E
E
E
E
E
out:
No
Yes
第四版代码(91pts):
过了样例及前三个 hack 数据。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid (l+r)>>1
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
ll t;
ll n;
string s,ss[110][5];
void solve()
{
map<string,ll>mp;
stack<string>q;
stack<ll>times;
cin>>n>>s;
ll sum=0,pd=0,ans=0,S=0;
forl(i,1,n)
{
cin>>ss[i][1];
if(ss[i][1]=="E" && sum && !q.empty() && !times.empty() && !pd)
{
string st=q.top();
mp[st]--;
q.pop();
sum--;
ll timetop=times.top();
if(timetop==1)
S--;
// S-=times.top();
times.pop();
}
else if(ss[i][1]=="E")
pd=1;
else
{
sum++;
ll num1=0,num2=0;
forl(j,2,4)
{
cin>>ss[i][j];
if(pd)
continue;
if(j==2)
{
q.push(ss[i][j]);
mp[ss[i][j]]++;
if(mp[ss[i][j]]>1)
pd=1;
}
if(j==3)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
forl(k,0,ss[i][j].size()-1)
num1*=10,num1+=ss[i][j][k]-'0';
else
num1=1e18;
}
if(j==4)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
forl(k,0,ss[i][j].size()-1)
num2*=10,num2+=ss[i][j][k]-'0';
else
num2=1e18;
if(num1>num2)
times.push(0);
else if(num2-num1>1e17)
{
if(times.empty())
times.push(1),S++,ans=max(ans,S);
else
{
if(times.top()==1 || times.top()==-1)
times.push(1),S++,ans=max(ans,S);
else
times.push(0);
}
}
else
times.push(-1);
ans=max(ans,S);
}
}
}
}
if(pd || sum)
cout<<"ERR\n";
else
{
string nums="",last="";
if(ans==0)
last="O(1)";
else
{
while(ans)
nums+=ans%10+'0',ans/=10;
reverse(nums.begin(),nums.end());
last="O(n^"+nums+")";
}
if(last==s)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
int main()
{
IOS;
t=1;
cin>>t;
while(t--)
solve();
/******************/
/*while(L<q[i].l) */
/* del(a[L++]);*/
/*while(L>q[i].l) */
/* add(a[--L]);*/
/*while(R<q[i].r) */
/* add(a[++R]);*/
/*while(R>q[i].r) */
/* del(a[R--]);*/
/******************/
QwQ;
}
此代码 hack 数据:
in:
9
22 O(n^7)
F a 70 94
F b 90 94
E
E
F a 29 n
F b 22 n
F c 4 27
F d 85 n
F e 24 n
F f 56 87
F g 19 66
F h 6 41
F i 78 92
F j 7 n
E
E
E
E
E
E
E
E
66 O(n^8)
F a 87 n
F b 70 n
F c 65 n
F d 85 n
F e 35 n
E
E
E
E
E
F a 33 59
F b 74 n
F c 3 n
F d 81 88
F e 82 97
F f 87 98
F g 49 88
F h 72 98
F i 56 n
F j 48 76
F k 90 n
F l 54 n
F m 86 n
E
E
E
E
E
E
E
E
E
E
E
E
E
F a 32 46
F b 56 n
F c 5 n
F d 65 75
F e 4 n
F f 78 n
F g 75 n
F h 82 n
F i 52 n
F j 53 n
E
E
E
E
E
E
E
E
E
E
E
E
F a 3 n
F b 6 n
F c 22 n
F d 42 n
E
E
E
E
60 O(n^11)
F a 46 n
F b 3 64
F c 8 n
F d 19 n
F e 30 n
F f 22 16
F g 40 n
F h 10 n
F i 25 n
F a 62 n
E
E
E
E
E
E
E
E
E
E
F a 81 n
F b 37 n
F c 44 n
F d 13 n
F e 56 94
E
E
E
E
E
F a 50 n
F b 75 n
F c 3 74
F d 58 n
F e 15 n
F f 43 n
F g 32 n
F h 25 35
F i 47 n
F j 56 n
F k 53 81
F l 63 n
F m 78 87
F o 73 n
F p 90 n
E
E
E
E
E
E
E
E
E
E
E
E
E
E
E
36 O(n^7)
F a 68 n
F b 42 n
F c 16 n
F d 26 89
E
E
E
E
F a 7 44
F b 13 60
F c 85 97
F d 38 74
F e 73 n
F f 65 83
F g 52 n
F h 3 5
F i 88 n
F j 24 n
F k 81 n
F l 1 n
F m 85 n
E
E
E
E
E
E
E
E
E
E
E
E
E
F a 36 67
E
84 O(n^11)
F a 85 86
F b 76 90
F c 45 75
F d 41 43
F e 87 96
F f 18 n
F g 15 76
F h 47 n
E
E
E
E
E
E
E
E
F a 61 n
F b 62 n
F c 3 32
F d 4 n
F e 18 n
F f 53 74
F g 64 n
F h 87 n
F i 77 n
F j 60 69
F k 67 96
F l 34 n
F m 62 n
E
E
E
E
E
E
E
E
E
E
E
E
E
F a 74 n
F b 17 n
F c 9 n
F d 43 n
F e 82 n
F f 57 65
F g 35 n
F h 29 n
F i 37 95
E
E
E
E
E
E
E
E
E
F a 31 n
F b 14 71
F c 74 n
F d 81 n
F e 8 n
F f 11 n
F g 29 n
F h 19 n
F i 60 n
F j 68 79
F k 63 n
F l 11 n
E
E
E
E
E
E
E
E
E
E
E
E
62 O(n^10)
F a 26 n
F b 84 n
F c 69 73
F d 59 n
F e 13 n
E
E
E
E
E
F a 46 n
F b 61 n
F c 47 n
F d 43 n
F e 77 n
F f 33 n
F g 32 n
F h 71 n
F i n n
F j 35 n
F k 47 86
F l 53 n
E
E
E
E
E
E
E
E
E
E
E
E
F a 31 38
F b 74 95
F c 6 66
F d 68 84
F e 72 n
F f 1 n
F g 47 89
F h 89 n
F i 5 n
F j 34 n
F k 2 n
F l 27 n
E
E
E
E
E
E
E
E
E
E
E
E
F a 33 58
F b 5 70
E
E
34 O(n^4)
F a 50 n
F b 6 78
F c 9 10
F d 6 n
F e 17 n
F f 24 n
E
E
E
E
E
E
F a 50 56
F b 2 17
F c 57 n
F d 46 86
F e 38 60
F f 56 n
F g 77 94
F h 26 71
F i 59 n
F j 22 40
F k 13 n
E
E
E
E
E
E
E
E
E
E
E
56 O(n^5)
F a 9 n
F b 64 n
F c 17 n
F d n 6
F e 59 n
F f 36 n
F g 48 64
F h 17 n
E
E
E
E
E
E
E
E
F a 20 n
F b 19 n
F c 18 55
F d 46 n
F e 58 70
F f 12 46
E
E
E
E
E
E
F a 20 n
F b 35 n
F c 44 67
F d 40 49
F e 71 75
F f 61 n
F g 76 n
F h 3 n
F i 99 60
F j 59 80
F k 27 n
F l 30 n
F m 5 n
F o 86 n
E
E
E
E
E
E
E
E
E
E
E
E
E
E
2 O(n^1)
F a n n
E
out:
ERR
ERR
ERR
Yes
No
Yes
Yes
Yes
No
第五版代码(100pts):
此代码 AC 了此题。
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid (l+r)>>1
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
ll t;
ll n;
string s,ss[110][5];
void solve()
{
map<string,ll>mp;
stack<string>q;
stack<ll>times;
cin>>n>>s;
ll sum=0,pd=0,ans=0,S=0;
forl(i,1,n)
{
cin>>ss[i][1];
if(ss[i][1]=="E" && sum && !q.empty() && !times.empty() && !pd)
{
string st=q.top();
mp[st]--;
q.pop();
sum--;
ll timetop=times.top();
if(timetop==1)
S--;
// S-=times.top();
times.pop();
}
else if(ss[i][1]=="E")
pd=1;
else
{
sum++;
ll num1=0,num2=0;
forl(j,2,4)
{
cin>>ss[i][j];
if(pd)
continue;
if(j==2)
{
q.push(ss[i][j]);
mp[ss[i][j]]++;
if(mp[ss[i][j]]>1)
pd=1;
}
if(j==3)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
forl(k,0,ss[i][j].size()-1)
num1*=10,num1+=ss[i][j][k]-'0';
else
num1=1e18;
}
if(j==4)
{
if(ss[i][j][0]>='0' && ss[i][j][0]<='9')
forl(k,0,ss[i][j].size()-1)
num2*=10,num2+=ss[i][j][k]-'0';
else
num2=1e18;
if(num1>num2)
times.push(0);
else if(!times.empty() && times.top()==0)
times.push(0);
else if(num2-num1>1e17)
{
if(times.empty())
times.push(1),S++,ans=max(ans,S);
else
{
if(times.top()==1 || times.top()==-1)
times.push(1),S++,ans=max(ans,S);
else
times.push(0);
}
}
else
times.push(-1);
ans=max(ans,S);
}
}
}
// cout<<S<<endl;
}
if(pd || sum)
cout<<"ERR\n";
else
{
string nums="",last="";
if(ans==0)
last="O(1)";
else
{
while(ans)
nums+=ans%10+'0',ans/=10;
reverse(nums.begin(),nums.end());
last="O(n^"+nums+")";
}
if(last==s)
cout<<"Yes\n";
else
cout<<"No\n";
}
}
int main()
{
IOS;
t=1;
cin>>t;
while(t--)
solve();
/******************/
/*while(L<q[i].l) */
/* del(a[L++]);*/
/*while(L>q[i].l) */
/* add(a[--L]);*/
/*while(R<q[i].r) */
/* add(a[++R]);*/
/*while(R>q[i].r) */
/* del(a[R--]);*/
/******************/
QwQ;
}