QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#551443 | #9255. Python Program | ucup-team3519# | TL | 1ms | 3588kb | C++20 | 2.4kb | 2024-09-07 16:56:38 | 2024-09-07 16:56:39 |
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 operator[](const std::string &name) {
if (isdigit(name)) {
return stoll(name);
}
return env[name];
}
void set(const std::string &name, i64 value) {
if (isdigit(name)) {
return;
}
env[name] = value;
}
};
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);
i64 ans = 0;
auto pred = [&](i64 i) -> bool {
return c > 0 ? i < b : i > b;
};
auto calc = [&](i64 a, i64 b, i64 c) -> i64 {
std::cerr << "Calc " << a << ' ' << b << ' ' << c << '\n';
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) {
env.set(outer_var, i);
ans += calc(env[d], env[e], env[f]);
}
std::cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
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: 1ms
memory: 3588kb
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: -100
Time Limit Exceeded
input:
ans=0 for i in range(1,1000000): for j in range(i,1,-1): ans+=j print(ans)