QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#762199 | #9255. Python Program | mobbb | AC ✓ | 4ms | 3780kb | C++20 | 2.0kb | 2024-11-19 14:08:38 | 2024-11-19 14:08:46 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
constexpr int inf = 1e9;
int main(){
std::string s;
std::cin >> s;
int a, b, c = 1, d, e, f = 1;
std::cin >> s;
std::string val;
std::cin >> val;
std::cin >> s;
std::cin >> s;
std::string cur;
bool ok = false;
int cnt = 0;
for (int i = 0; i < s.size(); i++){
if (ok){
if (s[i] == ',' || s[i] == ')'){
if (cnt == 0){
a = std::stoi(cur);
}else if (cnt == 1){
b = std::stoi(cur);
}else{
c = std::stoi(cur);
}
cnt++;
cur.clear();
}else{
cur += s[i];
}
}
if (s[i] == '('){
ok = true;
}
}
std::cin >> s;
std::cin >> s;
std::cin >> s;
std::cin >> s;
cur.clear();
ok = false;
cnt = 0;
for (int i = 0; i < s.size(); i++){
if (ok){
if (s[i] == ',' || s[i] == ')'){
if (cnt == 0){
if (cur == val){
d = inf;
}else{
// std::cerr << cur << '\n';
d = std::stoi(cur);
}
}else if (cnt == 1){
if (cur == val){
e = inf;
}else{
// std::cerr << cur << '\n';
e = std::stoi(cur);
}
}else{
if (cur == val){
f = inf;
}else{
// std::cerr << cur << '\n';
f = std::stoi(cur);
}
}
cnt++;
cur.clear();
}else{
cur += s[i];
}
}
if (s[i] == '('){
ok = true;
}
}
// std::cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << '\n';
ll ans = 0;
auto sign = [&](int x){
return (x > 0 ? 1 : -1);
};
for (int i = a; (c > 0 ? (i < b) : (i > b)); i += c){
ll td = d, te = e, tf = f;
if (td == inf) {
td = i;
}
if (te == inf) {
te = i;
}
if (tf == inf) {
tf = i;
}
// std::cerr << td << ' ' << te << ' ' << tf << '\n';
if ((te - td) * tf < 0) continue;
ll k = (te - td + (tf - sign(tf))) / tf;
// std::cerr << k << '\n';
ans += (td + (td + (k - 1) * tf)) * k / 2;
}
std::cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
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: 3552kb
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: 4ms
memory: 3544kb
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: 3556kb
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: 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