QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688710 | #9255. Python Program | real_sigma_team# | WA | 0ms | 3496kb | C++23 | 2.3kb | 2024-10-30 12:52:00 | 2024-10-30 12:52:00 |
Judging History
answer
#include <bits/stdc++.h>
int64_t calc(int d, int e, int f) {
int64_t res = 0;
if (f > 0) {
e--;
if (e < d) return 0;
int64_t qq = (e - d) / f;
return (2 * d + f * qq) * (qq + 1) / 2;
} else {
e++;
f = -f;
if (e > d) return 0;
int64_t qq = (d - e) / f;
return (2 * d - f * qq) * (qq + 1) / 2;
}
}
int32_t main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
std::string s;
std::getline(std::cin, s);
std::getline(std::cin, s);
int pos = s.find("range(");
pos += 6;
while (s[pos] != ',' && s[pos] != ')') {
a *= 10;
a += s[pos] - '0';
pos++;
}
pos++;
while (s[pos] != ',' && s[pos] != ')') {
b *= 10;
b += s[pos] - '0';
pos++;
}
if (s[pos] == ')') {
c = 1;
} else {
pos++;
bool minus = false;
if (s[pos] == '-') minus = true, pos++;
while (s[pos] != ',' && s[pos] != ')') {
c *= 10;
c += s[pos] - '0';
pos++;
}
if (minus) c *= -1;
}
std::getline(std::cin, s);
pos = s.find("range(");
pos += 6;
if ('0' <= s[pos]&& s[pos] <= '9') {
while (s[pos] != ',' && s[pos] != ')') {
d *= 10;
d += s[pos] - '0';
pos++;
}
} else {
d = -228;
pos++;
}
pos++;
if ('0' <= s[pos] && s[pos] <= '9') {
while (s[pos] != ',' && s[pos] != ')') {
e *= 10;
e += s[pos] - '0';
pos++;
}
} else {
e = -228;
pos++;
}
if (s[pos] == ')') {
f = 1;
} else {
pos++;
if (s[pos] == '-' || ('0' <= s[pos] && s[pos] <= '9')) {
bool minus = false;
if (s[pos] == '-') minus = true, pos++;
while (s[pos] != ',' && s[pos] != ')') {
f *= 10;
f += s[pos] - '0';
pos++;
}
if (minus) f *= -1;
} else {
f = -228;
}
}
// std::cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << std::endl;
int64_t ans = 0;
if (c > 0) {
for (int i = a; i < b; i += c) {
std::cout << i << ' ' << calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f) << std::endl;
ans += calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f);
}
} else {
for (int i = a; i > b; i += c) {
// std::cout << i << ' ' << calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f) << std::endl;
ans += calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f);
}
}
std::cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3496kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
1 8 2 8 16
result:
wrong answer 1st lines differ - expected: '16', found: '1 8'