QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637500 | #9255. Python Program | ucup-team4479# | AC ✓ | 3ms | 3864kb | C++23 | 2.5kb | 2024-10-13 13:05:55 | 2024-10-13 13:05:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9;
void range_to_string(string range, string &a, string &b, string &c) {
a = range.substr(range.find('(') + 1, range.find(',') - range.find('(') - 1);
range = range.substr(range.find(',') + 1, range.length() - range.find(',') - 1);
if (range.find(',') == string::npos) {
b = range.substr(0, range.find(')'));
c = "1";
} else {
b = range.substr(0, range.find(","));
c = range.substr(range.find(',') + 1, range.find(')') - range.find(',') - 1);
}
}
int main() {
cin.tie(nullptr) -> ios::sync_with_stdio(false);
cout.tie(0);
string A, B, C, D, E, F;
int a, b, c, d, e, f;
string rub;
cin >> rub;
cin >> rub;
string I;
cin >> I;
cin >> rub;
string range1;
cin >> range1;
range_to_string(range1, A, B, C);
a = stoi(A), b = stoi(B), c = stoi(C);
// cout << a << " " << b << " " << c << endl;
cin >> rub;
string J;
cin >> J;
cin >> rub;
string range2;
cin >> range2;
range_to_string(range2, D, E, F);
if (D == I) d = inf; else d = stoi(D);
if (E == I) e = inf; else e = stoi(E);
if (F == I) f = inf; else f = stoi(F);
// cout << d << " " << e << " " << f << endl;
cin >> rub;
cin >> rub;
long long ans = 0;
if (c >= 0) {
for (int i = a; i < b; i += c) {
int st = d, ed = e, dlt = f;
if (st == inf) st = i;
if (ed == inf) ed = i;
if (dlt == inf) dlt = i;
if (dlt > 0) {
ed--;
if (st > ed) continue;
} else {
ed++;
if (st < ed) continue;
}
ed = st + (ed - st) / dlt * dlt;
ans += 1ll * (st + ed) * ((ed - st) / dlt + 1) / 2;
}
} else {
for (int i = a; i > b; i += c) {
int st = d, ed = e, dlt = f;
if (st == inf) st = i;
if (ed == inf) ed = i;
if (dlt == inf) dlt = i;
if (dlt > 0) {
ed--;
if (st > ed) continue;
} else {
ed++;
if (st < ed) continue;
}
ed = st + (ed - st) / dlt * dlt;
ans += 1ll * (st + ed) * ((ed - st) / dlt + 1) / 2;
}
}
cout << ans << endl;
return 0;
}
/*
ans=0
for q in range(100,50,-1):
for i in range(q,q,q):
ans+=i
print(ans)
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
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: 3512kb
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: 0ms
memory: 3564kb
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: 3628kb
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: 3560kb
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