QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#616769 | #9255. Python Program | ucup-team4153# | AC ✓ | 76ms | 3616kb | C++20 | 1.8kb | 2024-10-06 11:18:40 | 2024-10-06 11:18:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
long long cal(int a,int b,int c){
if(c>=0){
b--;
if(a>b)return 0;
}else{
b++;
if(a<b)return 0;
}
int x=abs(b-a)/abs(c);
b=a+x*c;
return 1ll*(a+b)*(x+1)/2;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
string s;int sz;
getline(cin,s);
getline(cin,s);
sz=1;for(auto ch:s)if(ch==',')sz++;
string oth,name;
stringstream lop1(s);string a,b,c="1";
getline(lop1,oth,' ');
getline(lop1,name,' ');
getline(lop1,oth,' ');
getline(lop1,oth,'(');
getline(lop1,a,',');
if(sz==2)getline(lop1,b,')');
else if(sz==3){
getline(lop1,b,',');
getline(lop1,c,')');
}
int _a= stoi(a),_b= stoi(b),_c= stoi(c);
if(_c>=0){
_b--;
}else{
_b++;
}
// cout<<name<<' '<<a<<' '<<b<<' '<<c<<'\n';
getline(cin,s);
sz=1;for(auto ch:s)if(ch==',')sz++;
stringstream lop2(s);string d,e,f="1";
getline(lop2,oth,' ');
getline(lop2,oth,' ');
getline(lop2,oth,' ');
getline(lop2,oth,'(');
getline(lop2,d,',');
if(sz==2)getline(lop2,e,')');
else if(sz==3){
getline(lop2,e,',');
getline(lop2,f,')');
}
getline(cin,s);
getline(cin,s);
long long ans=0;
for(int i=_a;(_c>=0 && i<=_b)||(_c<0 && i>=_b);i+=_c){
vector<int>vec;
if(d==name)vec.push_back(i);
else vec.push_back(stoi(d));
if(e==name)vec.push_back(i);
else vec.push_back(stoi(e));
if(f==name)vec.push_back(i);
else vec.push_back(stoi(f));
// cout<<vec[0]<<' '<<vec[1]<<' '<<vec[2]<<' '<<cal(vec[0],vec[1],vec[2])<<'\n';
ans+=cal(vec[0],vec[1],vec[2]);
}
cout<<ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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: 3484kb
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: 71ms
memory: 3616kb
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: 12ms
memory: 3576kb
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: 76ms
memory: 3552kb
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