QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#617429 | #9255. Python Program | castc# | AC ✓ | 4ms | 3792kb | C++20 | 4.8kb | 2024-10-06 15:31:31 | 2024-10-06 15:31:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define int long long
const int inf = 1e9;
void solve() {
vector<string> s(5);
for(int i = 0; i < 5; i++) {
getline(cin, s[i]);
}
int a = inf, b = inf, c = inf, d = inf, e = inf, f = inf;
int lst = 15;
int cnt = 0;
char I = s[1][4], J = s[2][8];
auto get = [&](int i, int l, int r) -> int {
int flag = 0;
int fg = 1;
if(s[i][l] == '-') {
fg = -1;
l++;
}
for(int j = l; j < r; j++) {
if(!(s[i][j] >= '0' && s[i][j] <= '9')) {
flag = 1;
}
}
int z = inf;
if(!flag) {
z = stoi(s[i].substr(l, r - l));
} else {
z = -inf;
}
return fg * z;
};
for(int i = 15; i < (int)s[1].size(); i++) {
if(s[1][i] == ',' && cnt == 0) {
cnt++;
// a = stoi(s[1].substr(lst, i - lst));
a = get(1, lst, i);
lst = i + 1;
} else if((s[1][i] == ',' || s[1][i] == ')') && cnt == 1) {
cnt++;
// b = stoi(s[1].substr(lst, i - lst));
b = get(1, lst, i);
lst = i + 1;
} else if(s[1][i] == ')' && cnt == 2) {
cnt++;
// c = stoi(s[1].substr(lst, i - lst));
c = get(1, lst, i);
lst = i + 1;
}
}
if(c == inf) {
c = 1;
}
lst = 19;
cnt = 0;
for(int i = 19; i < (int)s[2].size(); i++) {
if(s[2][i] == ',' && cnt == 0) {
cnt++;
d = get(2, lst, i);
lst = i + 1;
} else if((s[2][i] == ',' || s[2][i] == ')') && cnt == 1) {
cnt++;
e = get(2, lst, i);
lst = i + 1;
} else if(s[2][i] == ')' && cnt == 2) {
cnt++;
f = get(2, lst, i);
lst = i + 1;
}
}
if(f == inf) {
f = 1;
}
int ans = 0;
if(d == -inf && e == -inf && f == -inf) {
// for(int i = a; i < b; i += c) {
// ans += i;
// }
} else if(d == -inf && e == -inf) {
// for(int i = a; i < b; i += c) {
// ans += i;
// }
} else if(d == -inf && f == -inf) {
for(int i = a; (c > 0 ? i < b : i > b); i += c) {
int a1 = i;
int n = (e - i + (i > 0 ? -1 : 1)) / i + (i > 0 ? i < e : i > e);
if(n <= 0) continue;
ans += a1 * n + n * (n - 1) / 2 * i;
}
} else if(e == -inf && f == -inf) {
for(int i = a; (c > 0 ? i < b : i > b); i += c) {
int a1 = d;
int n = (i - d + (i > 0 ? -1 : 1)) / i + (i > 0 ? d < i : d > i);
if(n <= 0) continue;
ans += a1 * n + n * (n - 1) / 2 * i;
// int a1 = d;
// int n = d / i;
// ans += a1 * n + n * (n - 1) / 2 * f;
}
} else if(d == -inf) {
// cerr << 'a';
// cerr << a << " " << b << " " << c << " " << d << " " << e << " " << f << "\n";
for(int i = a; (c > 0 ? i < b : i > b); i += c) {
int a1 = i;
int n = (e - i + (f > 0 ? -1 : 1)) / f + (f > 0 ? i < e : i > e);
if(n <= 0) continue;
// cerr << a1 << " " << n << "\n";
ans += a1 * n + n * (n - 1) / 2 * f;
}
} else if(e == -inf) {
for(int i = a; (c > 0 ? i < b : i > b); i += c) {
int a1 = d;
int n = (i - d + (f > 0 ? -1 : 1)) / f + (f > 0 ? d < i : d > i);
if(n <= 0) continue;
ans += a1 * n + n * (n - 1) / 2 * f;
// int a1 = d;
// int n = (i - d) / f;
// ans += a1 * n + n * (n - 1) / 2 * f;
}
} else if(f == -inf) {
for(int i = a; (c > 0 ? i < b : i > b); i += c) {
int a1 = d;
int n = (e - d + (i > 0 ? -1 : 1)) / i + (i > 0 ? d < e : d > e);
if(n <= 0) continue;
ans += a1 * n + n * (n - 1) / 2 * i;
// int a1 = d;
// int n = (e - d) / i;
// ans += a1 * n + n * (n - 1) / 2 * f;
}
} else {
for(int i = a; (c > 0 ? i < b : i > b); i += c) {
int a1 = d;
int n = (e - d + (f > 0 ? -1 : 1)) / f + (f > 0 ? d < e : d > e);
if(n <= 0) continue;
ans += a1 * n + n * (n - 1) / 2 * f;
}
}
cout << ans << "\n";
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// cout.tie(nullptr);
// sieve((int)1e5 + 9);
int T = 1;
// cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
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: 3496kb
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: 3596kb
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: 3784kb
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: 4ms
memory: 3792kb
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