QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#595318 | #9255. Python Program | DBsoleil# | AC ✓ | 23ms | 4108kb | C++20 | 1.7kb | 2024-09-28 13:25:14 | 2024-09-28 13:25:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct data_t {
string name;
string from, to;
int step;
data_t() = default;
data_t(string name, string from, string to, int step)
: name(name), from(from), to(to), step(step) { }
};
int main(void) {
string str; getline(cin, str);
auto parse = [&]()->data_t {
string str, trash, name;
string from, to, ste; int step;
getline(cin, str);
istringstream is(str);
is >> trash >> name; is >> trash;
char ch; is >> ch;
while (ch != '(') is >> ch; is >> ch;
while (ch != ',') from += ch, is >> ch; is >> ch;
while (ch != ',' && ch != ')') to += ch, is >> ch;
if (ch == ')') step = 1;
else { is >> ch; while (ch != ')') ste += ch, is >> ch; step = stoi(ste); }
return data_t(name, from, to, step);
};
auto print = [&](int64_t x) { exit(printf("%lld\n", x) & 0); };
auto A = parse();
auto B = parse();
int af = stoi(A.from), at = stoi(A.to);
if ((af < at) != (A.step > 0)) print(0);
auto get = [&](int f, int t, int s)->int64_t {
if ((f < t) != (s > 0)) return 0;
int r = 0;
if (f < t) r = (t - f + s - 1) / s;
else r = (f - t - s - 1) / -s;
int e = f + (r - 1) * s;
return (int64_t)(f + e) * r / 2;
};
auto calc = [&](int a)->int64_t {
int bf, bt;
if (B.from == A.name) bf = a, bt = stoi(B.to);
else if (B.to == A.name) bt = a, bf = stoi(B.from);
else bf = stoi(B.from), bt = stoi(B.to);
if ((bf < bt) != (B.step > 0)) return 0;
return get(bf, bt, B.step);
};
int64_t ans = 0;
for (int a = af; a != at && (a < at) == (A.step > 0); a += A.step) ans += calc(a);
print(ans);
return 0;
} // main
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4108kb
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: 3692kb
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: 16ms
memory: 3828kb
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: 6ms
memory: 3840kb
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: 23ms
memory: 3744kb
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