QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552063 | #9255. Python Program | ucup-team1198# | AC ✓ | 3ms | 3812kb | C++20 | 2.1kb | 2024-09-07 20:14:21 | 2024-09-07 20:14:21 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
long long get_sum(long long a, long long b, long long c) {
if (c > 0) {
if (b <= a)
return 0;
long long k = (b - a - 1) / c;
return (2 * a + k * c) * (k + 1) / 2;
} else {
if (b >= a)
return 0;
long long k = (a - b - 1) / (-c);
return (2 * a + k * c) * (k + 1) / 2;
}
}
const int NONE = 1'000'228;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
getline(cin, s); // ans=0
auto read_thing = []() {
string s;
getline(cin, s);
int cur = 0;
while (s[cur] != 'f')
++cur;
char var = s[cur + 4];
vector<int> ans(3, 1);
while (s[cur] != '(')
++cur;
++cur;
int t = 0;
ans[0] = 0;
bool neg = false;
while (true) {
if (s[cur] == ',') {
if (neg)
ans[t] *= -1;
neg = false;
++t;
ans[t] = 0;
} else if (s[cur] == ')') {
if (neg)
ans[t] *= -1;
break;
} else if (s[cur] == '-') {
neg = true;
} else {
if ('0' <= s[cur] && s[cur] <= '9')
ans[t] = ans[t] * 10 + (s[cur] - '0');
else
ans[t] = NONE;
}
++cur;
}
return make_pair(var, ans);
};
long long ans = 0;
auto [v1, l1] = read_thing();
auto [v2, l2] = read_thing();
long long a = l1[0], b = l1[1], c = l1[2];
long long d = l2[0], e = l2[1], f = l2[2];
if (c > 0) {
for (long long i = a; i < b; i += c) {
ans += get_sum(d == NONE ? i : d, e == NONE ? i : e, f == NONE ? i : f);
}
} else {
for (long long i = a; i > b; i += c) {
ans += get_sum(d == NONE ? i : d, e == NONE ? i : e, f == NONE ? i : f);
}
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 3528kb
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: 3808kb
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: 3752kb
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: 3524kb
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