QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#550718 | #9255. Python Program | ucup-team3584# | WA | 3ms | 3656kb | C++20 | 3.4kb | 2024-09-07 14:02:16 | 2024-09-07 14:02:16 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string op;
getline(cin, op);
getline(cin, op);
const ll inf = 1e18;
char i1, i2, i3;
ll a, b, c, d, e, f;
auto read = [&](int &i, ll &x) -> void {
bool minus = false;
if (op[i] == '-') minus = true, i += 1;
if (isdigit(op[i])) {
x = 0;
while (isdigit(op[i])) {
x = x * 10 + op[i] - '0';
i += 1;
}
if (minus) x = -x;
} else {
x = inf;
i += 1;
}
};
i1 = op[4];
for (int i = 0; i < op.size(); ++i) {
if (op.substr(i, 5) == "range") {
i += 6;
read(i, a);
if (op[i] == ',') {
i += 1;
read(i, b);
if (op[i] == ',') {
i += 1;
read(i, c);
} else {
c = 1;
}
}
break;
}
}
getline(cin, op);
i2 = op[8];
for (int i = 0; i < op.size(); ++i) {
if (op.substr(i, 5) == "range") {
i += 6;
read(i, d);
if (op[i] == ',') {
i += 1;
read(i, e);
if (op[i] == ',') {
i += 1;
read(i, f);
} else {
c = 1;
}
}
break;
}
}
getline(cin, op);
for (int i = 0; i < op.size(); ++i) {
if (op[i] == '=') i3 = op[i + 1];
}
ll ans = 0;
if (c > 0) {
for (ll i = a; i < b; i += c) {
ll D = (d == inf ? i : d);
ll E = (e == inf ? i : e);
ll F = (f == inf ? i : f);
if (F > 0) {
ll cnt = 0;
if (D < E) cnt = (E - D - 1) / F + 1;
if (i1 == i3) ans += cnt * i;
else if (cnt) {
ans += (D + D + (cnt - 1) * F) * cnt / 2;
}
} else {
ll cnt = 0;
if (D > E) cnt = (D - E - 1) / abs(F) + 1;
if (i1 == i3) ans += cnt * i;
else if (cnt) {
ans += (D + D + (cnt - 1) * F) * cnt / 2;
}
}
}
} else {
for (int i = a; i > b; i += c) {
ll D = (d == inf ? i : d);
ll E = (e == inf ? i : e);
ll F = (f == inf ? i : f);
if (F > 0) {
ll cnt = 0;
if (D < E) cnt = (E - D - 1) / F + 1;
if (i1 == i3) ans += cnt * i;
else {
ans += (D + D + (cnt - 1) * F) * cnt / 2;
}
} else {
ll cnt = 0;
if (D > E) cnt = (D - E - 1) / abs(F) + 1;
if (i1 == i3) ans += cnt * i;
else {
ans += (D + D + (cnt - 1) * F) * cnt / 2;
}
}
}
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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: 3656kb
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: 3548kb
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: -100
Wrong Answer
time: 2ms
memory: 3588kb
input:
ans=0 for i in range(31,321983,2): for j in range(313,382193): ans+=j print(ans)
output:
904360551174144
result:
wrong answer 1st lines differ - expected: '11756963404587200', found: '904360551174144'