QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765265 | #9255. Python Program | szy10010# | AC ✓ | 4ms | 3860kb | C++23 | 6.4kb | 2024-11-20 13:28:12 | 2024-11-20 13:28:15 |
Judging History
answer
#include<iostream>
#include<set>
#include<queue>
#include<map>
#include<cmath>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
#include<unordered_map>
#define pb push_back
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(),(x).end()
#define _for(i, a) for(int i = 0; i < (a); ++i)
#define _rep(i, a, b) for(int i = (a);i <= (b); ++i)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define u1 (u<<1)
#define u2 (u<<1|1)
//#define endl '\n'
using namespace std;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
const int P=1e9+7;
const int N=1e6+20,M=2*N;
int n,m,k,q[N];
int q1[5],q2[5];
int state,stateans;
char aa,bb,cc;
int deal0(string &s)
{
int res=0;
bool bl=false,fu=false;
_for(i,s.size())
{
if(s[i]=='-')fu=true;
if(isdigit(s[i]))bl=true;
if(bl)res=res*10+s[i]-'0';
}
if(fu)res=-res;
return res;
}
void deal1(string &s)
{
int now=0,idx=0;
bool fu=false;
_for(i,s.size())
{
if(s[i]==',')
{
if(fu)now=-now;
q1[idx++]=now,now=0,fu=false;
}
else
{
if(s[i]=='-')fu=true;
else now=now*10+s[i]-'0';
}
}
if(fu)now=-now;
q1[idx++]=now,now=0,fu=false;
}
void deal2(string &s)
{
int now=0,idx=0;
bool fu=false;
_for(i,s.size())
{
if(s[i]==',')
{
if(fu)now=-now;
q2[idx++]=now,now=0,fu=false;
}
else
{
if(s[i]=='-')fu=true;
else if(isdigit(s[i]))now=now*10+s[i]-'0';
else state|=(1<<(2-idx));
}
}
if(fu)now=-now;
q2[idx++]=now,now=0,fu=false;
}
int deal3(string &s)
{
int now=0;
bool bl=false,fu=false;
// cout<<"s3= "<<s<<endl;
_for(i,s.size())
{
if(s[i]=='=')bl=true;
else if(bl)
{
if(s[i]=='-')fu=true;
else if(isdigit(s[i]))now=now*10+s[i]-'0';
else stateans=1,cc=s[i];
}
}
if(fu)now=-now;
return now;
}
void solve(){
string s,s0,s1="",s2="",s3,s4;
bool bl=false;
getline(cin,s0);
getline(cin,s);
q1[2]=q2[2]=1;
_for(i,s.size())
{
if(i==4)aa=s[i];
if(i&&s[i]=='(')bl=true;
else
{
if(s[i]==')')break;
if(bl)s1.pb(s[i]);
}
}
getline(cin,s);
bl=false;
_for(i,s.size())
{
if(i==8)bb=s[i];
if(i&&s[i]=='(')bl=true;
else
{
if(s[i]==')')break;
if(bl)s2.pb(s[i]);
}
}
getline(cin,s);
s3=s.substr(8);
getline(cin,s4);
int res=deal0(s0);
deal1(s1);
deal2(s2);
int add=deal3(s3);
// cout<<s0<<endl<<s1<<endl<<s2<<endl<<s3<<endl<<s4<<endl;
// _for(i,3)cout<<q1[i]<<" ";
// cout<<endl;
// _for(i,3)cout<<q2[i]<<" ";
// cout<<endl;
// cout<<"State="<<state<<" Stateans="<<stateans<<endl;
if((q1[0]<q1[1]&&q1[2]<=0)||(q1[0]>=q1[1]&&q1[2]>=0))
{
;
}
else if(state==0)
{
for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
{
if(!q2[2])continue;
int cnt=abs((abs(q2[1]-q2[0])-1)/q2[2])+1;
if(!stateans)res+=add*cnt;
else
{
if(cc==aa)res+=i*cnt;
else res+=(q2[0]+(q2[0]+(cnt-1)*q2[2]))*cnt/2;
}
// for(int j=q2[0];q2[2]>0?j<q2[1]:j>q2[1];j+=q2[2])
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
}
else if(state==1)
{
for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
{
if(!i)continue;
q2[2]=i;
if(q2[2]<0&&q2[0]<=q2[1])continue;
if(q2[2]>0&&q2[0]>=q2[1])continue;
int cnt=abs((abs(q2[1]-q2[0])-1)/q2[2])+1;
if(!stateans)res+=add*cnt;
else
{
if(cc==aa)res+=i*cnt;
else res+=(q2[0]+(q2[0]+(cnt-1)*q2[2]))*cnt/2;
}
// for(int j=q2[0];i>0?j<q2[1]:j>q2[1];j+=i)
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
}
else if(state==2)
{
for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
{
if(!q2[2])continue;
q2[1]=i;
if(q2[2]<0&&q2[0]<=q2[1])continue;
if(q2[2]>0&&q2[0]>=q2[1])continue;
int cnt=abs((abs(q2[1]-q2[0])-1)/q2[2])+1;
if(!stateans)res+=add*cnt;
else
{
if(cc==aa)res+=i*cnt;
else res+=(q2[0]+(q2[0]+(cnt-1)*q2[2]))*cnt/2;
}
// for(int j=q2[0];q2[2]>0?j<i:j>i;j+=q2[2])
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
}
else if(state==3)
{
for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
{
if(!i)continue;
q2[1]=q2[2]=i;
if(q2[2]<0&&q2[0]<=q2[1])continue;
if(q2[2]>0&&q2[0]>=q2[1])continue;
int cnt=abs((abs(q2[1]-q2[0])-1)/q2[2])+1;
if(!stateans)res+=add*cnt;
else
{
if(cc==aa)res+=i*cnt;
else res+=(q2[0]+(q2[0]+(cnt-1)*q2[2]))*cnt/2;
}
// for(int j=q2[0];i>0?j<i:j>i;j+=i)
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
}
else if(state==4)
{
for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
{
if(!q2[2])continue;
q2[0]=i;
if(q2[2]<0&&q2[0]<=q2[1])continue;
if(q2[2]>0&&q2[0]>=q2[1])continue;
int cnt=abs((abs(q2[1]-q2[0])-1)/q2[2])+1;
// cout<<i<<" "<<"cnt="<<cnt<<endl;
if(!stateans)res+=add*cnt;
else
{
if(cc==aa)res+=i*cnt;
else res+=(q2[0]+(q2[0]+(cnt-1)*q2[2]))*cnt/2;
}
// cout<<"nowres"<<res<<endl;
// for(int j=i;q2[2]>0?(j<q2[1]):(j>q2[1]);j+=q2[2])
// {
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
// }
}
}
else if(state==5)
{
for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
{
if(!i)continue;
q2[0]=q2[2]=i;
if(q2[2]<0&&q2[0]<=q2[1])continue;
if(q2[2]>0&&q2[0]>=q2[1])continue;
int cnt=abs((abs(q2[1]-q2[0])-1)/q2[2])+1;
if(!stateans)res+=add*cnt;
else
{
if(cc==aa)res+=i*cnt;
else res+=(q2[0]+(q2[0]+(cnt-1)*q2[2]))*cnt/2;
}
// for(int j=i;i>0?j<q2[1]:j>q2[1];j+=i)
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
}
else if(state==6)
{
// for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
// for(int j=i;j<i;j+=q2[2])
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
else
{
// for(int i=q1[0];q1[0]<q1[1]?i<q1[1]:i>q1[1];i+=q1[2])
// for(int j=i;j<i;j+=i)
// if(!stateans)res+=add;
// else
// {
// if(cc==aa)res+=i;
// else res+=j;
// }
}
cout<<res;
}
signed main(){
IOS;
int T=1;
// cin>>T;
_rep(i,1,T){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
ans=0 for q in range(100,50,-1): for i in range(q,77,20): ans+=i print(ans)
output:
2092
result:
ok single line: '2092'
Test #3:
score: 0
Accepted
time: 4ms
memory: 3668kb
input:
ans=0 for i in range(1,1000000): for j in range(i,1,-1): ans+=j print(ans)
output:
166666666665500001
result:
ok single line: '166666666665500001'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3792kb
input:
ans=0 for i in range(31,321983,2): for j in range(313,382193): ans+=j print(ans)
output:
11756963404587200
result:
ok single line: '11756963404587200'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3636kb
input:
ans=0 for i in range(1,1000000): for j in range(i,114514,-1): ans+=j print(ans)
output:
160610445975856765
result:
ok single line: '160610445975856765'
Extra Test:
score: 0
Extra Test Passed