QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801360#9255. Python Programkjhhjki#AC ✓3ms3860kbC++202.2kb2024-12-06 21:44:072024-12-06 21:44:09

Judging History

你现在查看的是最新测评结果

  • [2024-12-06 21:44:09]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3860kb
  • [2024-12-06 21:44:07]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using f64 = long double;

template<typename T, typename U>
void chkmax(T &a, U b) { if(a < b) a = b; }
template<typename T, typename U>
void chkmin(T &a, U b) { if(a > b) a = b; }

constexpr int P = 998244353;

void init() { }

void solve()
{
    std::string s;
    std::getline(std::cin, s);
    int *a[2], *b[2], *c[2];
    int cur = -1;
    auto get = [&](int p, int **x) {
        if (std::isalpha(s[p])) {
            *x = &cur;
            ++p;
        } else {
            *x = new int(0);
            int f = 1;
            if (s[p] == '-') {
                f = -1;
                ++p;
            }
            while (std::isdigit(s[p])) {
                **x = 10 * (**x) + s[p] - '0';
                ++p;
            }
            **x *= f;
        }
        return p;
    };
    for (int i = 0; i < 2; ++i) {
        std::getline(std::cin, s);
        int p = s.find('(') + 1;
        p = get(p, &a[i]) + 1;
        p = get(p, &b[i]) + 1;
        get(p, &c[i]);
        if (c[i][0] == 0) {
            c[i][0] = 1;
        }
    }
    // std::cout << a[1][0] << ' ' << b[1][0] << ' ' << c[1][0] << '\n';
    // std::cout << a[0][0] << ' ' << b[0][0] << ' ' << c[0][0] << '\n';
    i64 ans = 0;
    for (cur = *a[0]; *c[0] > 0? cur < *b[0]: cur > *b[0]; cur += *c[0]) {
        int d = a[1][0], e = b[1][0], f = c[1][0];
        if (f < 0) {
            i64 n = (d - e - 1) / -f + 1, lst = d + n * f - f;
            if (e >= d) {
                continue;
            }
            ans += (d + lst) * n / 2;
        } else {
            i64 n = (e - d - 1) / f + 1, lst = d + n * f - f;
            if (e <= d) {
                continue;
            }
            ans += (d + lst) * n / 2;
        }
    }
    std::cout << ans << '\n';
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    init();
    int T = 1;
    // std::cin >> T;
    while(T --) solve();
    return 0;
}
/*
ans=0
for a in range(1,3):
    for b in range(5,1,-2):
        ans+=b
print(ans)

ans=0
for q in range(100,50,-1):
    for i in range(q,77,20):
        ans+=i
print(ans)
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3568kb

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: 3600kb

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: 3ms
memory: 3836kb

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: 3860kb

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: 0ms
memory: 3568kb

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