QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671847 | #9255. Python Program | Nana7# | AC ✓ | 5ms | 3792kb | C++14 | 2.6kb | 2024-10-24 14:42:01 | 2024-10-24 14:42:01 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
#define I inline
#define int long long
#define inf 1e7
#define For(a,b,c) for(int i=a;i<b;i+=c)
#define Rep(a,b,c) for(int i=a;i>b;i+=c)
using namespace std;
string s[6];
I int qsum(int a,int b,int c=1) {
if(c<0) {
if(a<=b) return 0;
int cnt=(b-a)/c;
if((b-a)%c==0) cnt--;
int mx=a+cnt*c;
return (mx+a)*(cnt+1)/2;
} else {
if(a>=b) return 0;
int cnt=(b-a)/c;
if((b-a)%c==0) cnt--;
int mx=a+cnt*c;
return (mx+a)*(cnt+1)/2;
}
}
I int sum(int a,int b,int c=1) { //cout<<a<<' '<<b<<' '<<c<<endl;
if(c>0) {
int res=0;
for(int i=a;i<b;i+=c) {
res+=i;
}
return res;
} else {
int res=0;
for(int i=a;i>b;i+=c) { //cout<<i<<endl;
res+=i;
}
return res;
}
}
I bool isc(char x) {
return x>='a'&&x<='z';
}
I vector<int> deal(string x) {
vector<int> ret;
int j=0;
while(x[j]!='(') j++;
j++;
int numb=0,sig=1;
if(x[j]=='-') {
sig=-1;
j++;
}
if(isc(x[j])) {
ret.push_back(inf);
j++;
} else {
for(;;++j) {
if(x[j]==','||x[j]==')') break;
else numb=numb*10+x[j]-'0';
}
ret.push_back(sig*numb);
}
j++; numb=0; sig=1;
if(x[j]=='-') {
sig=-1;
j++;
}
if(isc(x[j])) {
ret.push_back(inf);
j++;
} else {
for(;;++j) {
if(x[j]==','||x[j]==')') break;
else numb=numb*10+x[j]-'0';
}
ret.push_back(sig*numb);
}
if(x[j]==')') return ret;
j++; numb=0; sig=1;
if(x[j]=='-') {
sig=-1;
j++;
}
if(isc(x[j])) {
ret.push_back(inf);
j++;
} else {
for(;;++j) {
if(x[j]==','||x[j]==')') break;
else numb=numb*10+x[j]-'0';
}
ret.push_back(sig*numb);
}
return ret;
}
signed main()
{
for(int i=1;i<=5;++i) getline(cin,s[i]);
// for(int i=1;i<=5;++i) cout<<s[i]<<endl;
int ans=0;
vector<int> v1 = deal(s[2]);
vector<int> v2 = deal(s[3]);
if(v1.size()==2) v1.push_back(1);
if(v2.size()==2) v2.push_back(1);
vector<int> nowv2=v2;
// for(auto &t:v1) cout<<t<< ' '; cout<<endl;
// for(auto &t:v2) cout<<t<<' '; cout<<endl;
if(v1[2]>0) {
For(v1[0],v1[1],v1[2]) {
for(int j=0;j<3;++j) {
if(v2[j]==inf) nowv2[j]=i;
else nowv2[j]=v2[j];
}
//for(auto &t:nowv2) //cout<<t<<' '; cout<<endl;
ans+=qsum(nowv2[0],nowv2[1],nowv2[2]);
}
} else {
Rep(v1[0],v1[1],v1[2]) { //cout<<i<<endl;
for(int j=0;j<3;++j) {
if(v2[j]==inf) nowv2[j]=i;
else nowv2[j]=v2[j];
}
ans+=qsum(nowv2[0],nowv2[1],nowv2[2]);
}
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 3752kb
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: 5ms
memory: 3572kb
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: 2ms
memory: 3512kb
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