QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#552848 | #9255. Python Program | ucup-team3617# | AC ✓ | 4ms | 12596kb | C++20 | 1.9kb | 2024-09-08 03:03:15 | 2024-09-08 03:03:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll DUMMY = 1e18;
ll terms(ll start, ll delta, ll its) {
ll ans = start * its;
ans += delta * (its * (its - 1)) / 2;
return ans;
}
ll get(string s) {
for (char c : s) {
if (c == '-') continue;
if ('0' <= c && c <= '9') continue;
return DUMMY;
}
return atoll(s.c_str());
}
array<ll,3> extract(string s) {
int comma = find(s.begin(), s.end(), ',') - s.begin();
string bf, af;
int ptr = comma;
while (s[ptr - 1] != '(') {
bf.push_back(s[--ptr]);
}
ptr = comma;
while (s[ptr + 1] != ')' && s[ptr + 1] != ',') {
af.push_back(s[++ptr]);
}
reverse(bf.begin(), bf.end());
string diff;
if (s[++ptr] == ',') {
while (s[ptr + 1] != ')') {
diff.push_back(s[++ptr]);
}
}
else diff = "1";
return {get(bf), get(af), get(diff)};
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
string cur;
getline(cin, cur);
getline(cin, cur);
auto [a, b, c] = extract(cur);
getline(cin, cur);
auto [D, E, F] = extract(cur);
vector<ll> seq;
if (c > 0) {
for (ll i = a; i < b; i += c) {
seq.push_back(i);
}
}
else {
for (ll i = a; i > b; i += c) {
seq.push_back(i);
}
}
ll ans = 0;
for (ll x : seq) {
ll d = (D == DUMMY ? x : D);
ll e = (E == DUMMY ? x : E);
ll f = (F == DUMMY ? x : F);
if (f > 0) {
ll st = d;
ll its = (max(0ll, e - d) + f - 1) / f;
ans += terms(st, f, its);
}
else {
ll st = d;
ll its = (max(0ll, d - e) + (-f) - 1) / (-f);
ans += terms(st, f, its);
}
}
cout << ans << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
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: 3780kb
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: 11780kb
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: 5236kb
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: 12596kb
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