QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552041 | #9255. Python Program | ucup-team3670# | AC ✓ | 58ms | 3832kb | C++17 | 1.5kb | 2024-09-07 20:01:02 | 2024-09-07 20:01:03 |
Judging History
answer
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
using namespace std;
vector<string> parse(string s){
while (!s.empty() && s[0] == ' ') s.erase(s.begin());
while (!s.empty() && s.back() == ' ') s.pop_back();
vector<string> res;
string t;
int cnt = 0;
forn(i, s.size()){
if (s[i] == ' ' || s[i] == '(' || s[i] == ',' || s[i] == ')'){
++cnt;
if (cnt == 2 || cnt == 5 || cnt == 6 || cnt == 7)
res.push_back(t);
t = "";
}
else{
t += s[i];
}
}
if (res.size() != 4){
assert(res.size() == 3);
res.push_back("1");
}
return res;
}
int eval(string a, string b, int val){
return a == b ? val : stoi(a);
}
bool ok(int i, int r, int s){
if (s > 0)
return i < r;
return i > r;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;
getline(cin, s);
getline(cin, s);
auto ss = parse(s);
getline(cin, s);
auto tt = parse(s);
int L = stoi(ss[1]);
int R = stoi(ss[2]);
int S = stoi(ss[3]);
long long ans = 0;
for (int i = L; ok(i, R, S); i += S){
int lf = eval(tt[1], ss[0], i);
int rg = eval(tt[2], ss[0], i);
int st = eval(tt[3], ss[0], i);
int coef = 1;
if (st < 0){
lf = -lf;
rg = -rg;
st = -st;
coef = -1;
}
rg -= 1;
if (lf <= rg){
int fst = lf;
int cnt = (rg - lf) / st;
int lst = fst + cnt * st;
ans += coef * ((fst + lst) * 1ll * (cnt + 1) / 2);
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3484kb
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: 3488kb
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: 50ms
memory: 3580kb
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: 12ms
memory: 3832kb
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: 58ms
memory: 3788kb
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