QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707346 | #9255. Python Program | cyc_43346# | AC ✓ | 3ms | 3780kb | C++14 | 3.3kb | 2024-11-03 15:35:43 | 2024-11-03 15:35:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int read()
{
int res = 0 , x = 1;
char ch = getchar();
while(ch > '9' || ch < '0')
{
if(ch == '-')
{
x = -1;
}
ch = getchar();
}
while(ch >= '0' && ch <= '9')
{
res = res * 10 + ch - '0';
ch = getchar();
}
return res * x;
}
string b;
bool is_digit(string a){
if(a==b)return false;
return true;
}
int get_digit(string a){
int k = 1;
int now=0;
if(a[0]=='-'){
k=-1;
now++;
}
int ans=0;
for(;now<a.size();now++){
ans=ans*10+(a[now]-'0');
}
return k*ans;
}
int fir[3];
int sec[3];
void solve()
{
string a;
cin>>a;
cin>>a;
cin>>b;
cin>>a;
cin>>a;
int l=0,r=0;
int now=0;
fir[2]=sec[2]=1;
for(int i=6;i<a.size();i++){
l=i;
while(i<a.size()&&a[i]!=','&&a[i]!=')'){
r=i;
i++;
}
if(is_digit(a.substr(l,r-l+1))){
fir[now]=get_digit(a.substr(l,r-l+1));
}
else{
fir[now]=-1e7;
}
now++;
if(a[i]==')')break;
}
cin>>a;
cin>>a;
cin>>a;
cin>>a;
now=0;
for(int i=6;i<a.size();i++){
l=i;
while(i<a.size()&&a[i]!=','&&a[i]!=')'){
r=i;
i++;
}
if(is_digit(a.substr(l,r-l+1))){
sec[now]=get_digit(a.substr(l,r-l+1));
}
else{
sec[now]=-1e7;
}
now++;
if(a[i]==')')break;
}
ll ans=0;
if(fir[2]>0){
ll sa,sb,sc;
for(int i=fir[0];i<fir[1];i+=fir[2]){
if(sec[0]==-1e7){
sa = i;
}
else sa = sec[0];
if(sec[1]==-1e7){
sb = i;
}
else sb = sec[1];
if(sec[2]==-1e7){
sc = i;
}
else sc = sec[2];
ll n=0;
if(sc>0){
if(sa>=sb)continue;
n = (sb-sa-1)/sc+1;
}
if(sc<0){
if(sb>=sa)continue;
n = (sa-sb-1)/-sc+1;
}
if(n<=0)continue;
//cout<<sa<<" "<<sb<<" "<<sc<<" "<<n<<endl;
ans +=n*sa+n*(n-1)*sc/2;
}
}
else{
ll sa,sb,sc;
for(int i=fir[0];i>fir[1];i+=fir[2]){
if(sec[0]==-1e7){
sa = i;
}
else sa = sec[0];
if(sec[1]==-1e7){
sb = i;
}
else sb = sec[1];
if(sec[2]==-1e7){
sc = i;
}
else sc = sec[2];
ll n=0;
if(sc>0){
if(sa>=sb)continue;
n = (sb-sa-1)/sc+1;
}
if(sc<0){
if(sb>=sa)continue;
n = (sa-sb-1)/-sc+1;
}
if(n<=0)continue;
ans +=n*sa+n*(n-1)*sc/2;
}
}
cin>>a;
cin>>a;
cout<<ans<<endl;
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
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: 3584kb
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: 3ms
memory: 3580kb
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: 0ms
memory: 3744kb
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: 3596kb
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