QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591345 | #9255. Python Program | zlxFTH# | AC ✓ | 84ms | 3804kb | C++14 | 2.1kb | 2024-09-26 15:30:05 | 2024-09-26 15:30:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(0)->sync_with_stdio(0);
auto input = [&]() {
string s;
getline(cin, s);
return s;
};
input();
string s1 = input();
string s2 = input();
auto p1 = s1.find("(");
auto p2 = s1.find(",", p1);
int l = stoi(s1.substr(p1 + 1, p2 - p1 - 1));
int r, c;
if (s1.find(",", p2 + 1) == string::npos) {
auto p3 = s1.find(")", p2 + 1);
r = stoi(s1.substr(p2 + 1, p3 - p2 - 1));
c = 1;
} else {
auto p3 = s1.find(",", p2 + 1);
r = stoi(s1.substr(p2 + 1, p3 - p2 - 1));
auto p4 = s1.find(")", p3 + 1);
c = stoi(s1.substr(p3 + 1, p4 - p3 - 1));
}
auto tar = s1[4];
i64 ans = 0;
auto calc = [&](i64 i) {
i64 x, y, d;
auto p1 = s2.find("(");
auto p2 = s2.find(",", p1);
if (s2[p1 + 1] == tar) {
x = i;
} else {
x = stoi(s2.substr(p1 + 1, p2 - p1 - 1));
}
if (s2.find(",", p2 + 1) == string::npos) {
auto p3 = s2.find(")", p2 + 1);
if (s2[p2 + 1] == tar) {
y = i;
} else {
y = stoi(s2.substr(p2 + 1, p3 - p2 - 1));
}
d = 1;
} else {
auto p3 = s2.find(",", p2 + 1);
if (s2[p2 + 1] == tar) {
y = i;
} else {
y = stoi(s2.substr(p2 + 1, p3 - p2 - 1));
}
auto p4 = s2.find(")", p3 + 1);
if (s2[p3 + 1] == tar) {
d = i;
} else {
d = stoi(s2.substr(p3 + 1, p4 - p3 - 1));
}
}
// cerr << i << " " << x << " " << y << " " << d << "\n";
if (!d) return;
if (d > 0 && x < y) {
i64 cnt = (y - x - 1) / d + 1;
ans += (x + x + (cnt - 1) * d) * cnt / 2;
}
if (d < 0 && x > y) {
i64 cnt = (x - y - 1) / (-d) + 1;
// cerr << cnt << "\n";
ans += (x + x + (cnt - 1) * d) * cnt / 2;
}
};
if (c > 0) {
for (int i = l; i < r; i += c) {
calc(i);
}
}
if (c < 0) {
for (int i = l; i > r; i += c) {
calc(i);
}
}
// cerr << l << " " << r << " " << c << "\n";
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 3804kb
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: 3488kb
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: 13ms
memory: 3532kb
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: 84ms
memory: 3488kb
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