QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732420 | #9255. Python Program | Rosmontispes# | AC ✓ | 36ms | 3780kb | C++20 | 2.8kb | 2024-11-10 14:29:15 | 2024-11-10 14:29:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;
void solve()
{
string s,l1,l2,tmp;
getline(cin,tmp);
getline(cin,l1);
getline(cin,l2);
getline(cin,tmp);
getline(cin,tmp);
string I = l1.substr(4,1);
string J = l2.substr(8,1);
// cerr<<I<<" "<<J<<"\n";
string a,b,c,d,e,f;
auto it = l1.find('(',0),itt = l1.find(',',it);
a = l1.substr(it + 1,itt - it - 1);
it = itt;
if(itt = l1.find(',',it + 1) == string::npos){
itt = l1.find(')',it + 1);
b = l1.substr(it + 1,itt - it - 1);
c = '1';
}else{
itt = l1.find(',',it + 1);
b = l1.substr(it + 1,itt - it - 1);
it = itt;
itt = l1.find(')',it + 1);
c = l1.substr(it + 1,itt - it - 1);
}
it = l2.find('(',0),itt = l2.find(',',it);
d = l2.substr(it + 1,itt - it - 1);
it = itt;
if(itt = l2.find(',',it + 1) == string::npos){
itt = l2.find(')',it + 1);
e = l2.substr(it + 1,itt - it - 1);
f = '1';
}else{
itt = l2.find(',',it + 1);
e = l2.substr(it + 1,itt - it - 1);
it = itt;
itt = l2.find(')',it + 1);
f = l2.substr(it + 1,itt - it - 1);
}
int ans = 0;
int A = stoi(a),B = stoi(b),C = stoi(c);
if(C > 0){
for(int i = A;i < B;i += C){
int D,E,F;
D = d == I?i:stoi(d);
E = e == I?i:stoi(e);
F = f == I?i:stoi(f);
if(F > 0){
if(D < E){
int k = (E - D - 1) / F;
ans += 1LL * (D + D + k * F) * (k + 1) / 2;
}
} else {
if(D > E){
int k = (D - E - 1) / (-F);
ans += 1LL * (D - k * (-F) + D) * (k + 1) / 2;
}
}
}
} else {
for(int i = A;i > B;i += C){
int D,E,F;
D = d == I?i:stoi(d);
E = e == I?i:stoi(e);
F = f == I?i:stoi(f);
if(F > 0){
if(D < E){
int k = (E - D - 1) / F;
ans += 1LL * (D + D + k * F) * (k + 1) / 2;
}
} else {
if(D > E){
int k = (D - E - 1) / (-F);
ans += 1LL * (D - k * (-F) + D) * (k + 1) / 2;
}
}
}
}
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
solve();
}
// ans=0
// for q in range(100,50,-1):
// for i in range(q,77,20):
// ans+=i
// print(ans)
// ans=0
// for a in range(1,3):
// for b in range(5,1,-2):
// ans+=b
// print(ans)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 3576kb
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: 30ms
memory: 3512kb
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: 9ms
memory: 3780kb
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: 36ms
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