QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628623 | #9255. Python Program | youthpaul | AC ✓ | 4ms | 3840kb | C++20 | 2.9kb | 2024-10-10 21:16:04 | 2024-10-10 21:16:05 |
Judging History
answer
#include<bits/stdc++.h>
#define fore(i,l,r) for(int i=(int)(l);i<(int)(r);++i)
#define fi first
#define se second
#define endl '\n'
#define ull unsigned long long
#define ALL(v) v.begin(), v.end()
#define Debug(x, ed) std::cerr << #x << " = " << x << ed;
const int INF=0x3f3f3f3f;
const long long INFLL=1e18;
typedef long long ll;
std::tuple<int, int, int> get(const std::string& s){
int a = 0, b = 0, c = 1;
int i = 0;
while(s[i] != '(') ++i;
++i;
if(isalpha(s[i])){
a = INF;
while(s[i] != ',') ++i;
}
else{
int j = i;
while(s[i] != ',') ++i;
a = atoi(s.substr(j, i - j).c_str());
}
++i;
if(isalpha(s[i])){
b = INF;
while(s[i] != ',' && s[i] != ')') ++i;
}
else{
int j = i;
while(s[i] != ',' && s[i] != ')') ++i;
b = atoi(s.substr(j, i - j).c_str());
}
if(s[i] == ')') return {a, b, c};
++i;
if(isalpha(s[i])){
c = INF;
}
else{
int j = i;
while(s[i] != ')') ++i;
c = atoi(s.substr(j, i - j).c_str());
}
return {a, b, c};
}
ll check(int x, int i){
if(x == INF) return i;
return x;
}
ll num(ll a, ll b, ll c){
if(c > 0){
if(a >= b) return 0;
return (b - a + c - 1) / c;
}
else{
if(a <= b) return 0;
c = -c;
return (a - b + c - 1) / c;
}
}
ll cal(ll a, ll b, ll c){
ll k = num(a, b, c);
if(!k) return 0;
ll at = a + (k - 1) * c;
return (a + at) * k / 2;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::string s, t, r, u;
std::getline(std::cin, s);
std::getline(std::cin, s);
std::getline(std::cin, t);
std::getline(std::cin, r);
std::getline(std::cin, u);
auto [a, b, c] = get(s);
auto [d, e, f] = get(t);
bool isj = true;
std::string vi;
int idx = 0;
while(s[idx] != ' ') ++idx;
++idx;
int j = idx;
while(s[j + 1] != ' ') ++j;
vi = s.substr(idx, j - idx + 1);
if(r.back() == '\n') r.pop_back();
if(r.substr(5) == vi) isj = false;
ll ans = 0;
if(c > 0){
for(int i = a; i < b; i += c){
ll x = check(d, i);
ll y = check(e, i);
ll z = check(f, i);
if(isj){
ans += cal(x, y, z);
}
else{
ans += num(x, y, z) * i;
}
}
}
else{
for(int i = a; i > b; i += c){
ll x = check(d, i);
ll y = check(e, i);
ll z = check(f, i);
if(isj){
ans += cal(x, y, z);
}
else{
ans += num(x, y, z) * i;
std::cerr << num << endl;
}
}
}
std::cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 3544kb
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: 3840kb
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: 0ms
memory: 3500kb
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: 3556kb
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