QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#551530 | #9255. Python Program | ucup-team3519# | AC ✓ | 4ms | 3804kb | C++20 | 2.7kb | 2024-09-07 17:14:48 | 2024-09-07 17:14:49 |
Judging History
answer
#include <bits/stdc++.h>
std::string read_token(bool noendl = false) {
char ch = std::cin.get();
bool minus = false;
while (!isdigit(ch) && !isalpha(ch)) {
if (ch == '\n' && noendl) {
return "1";
}
if (ch == '-') {
minus = true;
}
ch = std::cin.get();
}
std::string str;
while (isdigit(ch) || isalpha(ch)) {
str += ch;
ch = std::cin.get();
}
return (minus ? "-" : "") + str;
}
bool isdigit(const std::string &str) {
for (auto i : str) {
if (!isdigit(i) && i != '-') {
return false;
}
}
return true;
}
using i64 = int64_t;
struct Env {
// std::unordered_map<std::string, i64> env;
i64 v{0};
i64 operator[](const std::string &name) {
if (isdigit(name)) {
return stoll(name);
}
return v;
}
void set(const std::string &name, i64 value) {
if (isdigit(name)) {
return;
}
v = value;
}
};
constexpr i64 INF = 1e18;
int main() {
Env env;
// LINE 1
auto name = read_token();
env.set(name, stoi(read_token()));
// LINE 2
read_token();
std::string outer_var = read_token();
read_token();
read_token();
i64 a = env[read_token()];
i64 b = env[read_token()];
i64 c = env[read_token(true)];
// LINE 3
read_token();
std::string inner_var = read_token();
read_token();
read_token();
std::string d = read_token();
std::string e = read_token();
std::string f = read_token(true);
bool td = isdigit(d);
bool te = isdigit(e);
bool tf = isdigit(f);
i64 vd = td ? stoll(d) : INF;
i64 ve = te ? stoll(e) : INF;
i64 vf = tf ? stoll(f) : INF;
i64 ans = 0;
auto pred = [&](i64 i) -> bool {
return c > 0 ? i < b : i > b;
};
auto calc = [&](i64 a, i64 b, i64 c) -> i64 {
if (c > 0) {
if (a >= b) {
return 0;
}
int n = (b - a - 1) / c;
return (a + a + c * n) * (n + 1) / 2;
} else {
if (a <= b) {
return 0;
}
c = -c;
int n = (a - b - 1) / c;
return (a + a - c * n) * (n + 1) / 2;
}
};
for (i64 i = a; pred(i); i += c) {
if (!td) {
vd = i;
}
if (!te) {
ve = i;
}
if (!tf) {
vf = i;
}
ans += calc(vd, ve, vf);
}
std::cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3608kb
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: 3516kb
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: 3804kb
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: 3772kb
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