QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550584#9255. Python Programucup-team004#AC ✓42ms3812kbC++201.8kb2024-09-07 13:31:302024-09-07 13:31:30

Judging History

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

  • [2024-09-07 13:31:30]
  • 评测
  • 测评结果:AC
  • 用时:42ms
  • 内存:3812kb
  • [2024-09-07 13:31:30]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::string s;
    std::cin >> s;
    std::cin >> s;
    std::cin >> s;
    std::cin >> s;
    std::cin >> s;
    
    std::string a, b, c, d, e, f;
    
    int i;
    s = s.substr(6);
    s = s.substr(0, s.find(')'));
    i = s.find(',');
    a = s.substr(0, i);
    s = s.substr(i + 1);
    i = s.find(',');
    if (i == -1) {
        b = s;
        c = "1";
    } else {
        b = s.substr(0, i);
        c = s.substr(i + 1);
    }
    
    std::cin >> s;
    std::cin >> s;
    std::cin >> s;
    std::cin >> s;
    
    s = s.substr(6);
    s = s.substr(0, s.find(')'));
    i = s.find(',');
    d = s.substr(0, i);
    s = s.substr(i + 1);
    i = s.find(',');
    if (i == -1) {
        e = s;
        f = "1";
    } else {
        e = s.substr(0, i);
        f = s.substr(i + 1);
    }
    
    std::cin >> s;
    std::cin >> s;
    
    i64 ans = 0;
    int va = std::stoi(a);
    int vb = std::stoi(b);
    int vc = std::stoi(c);
    for (int i = va; (vc > 0 ? i < vb : i > vb); i += vc) {
        int vd = std::isalpha(d[0]) ? i : std::stoi(d);
        int ve = std::isalpha(e[0]) ? i : std::stoi(e);
        int vf = std::isalpha(f[0]) ? i : std::stoi(f);
        
        if (vf > 0) {
            if (vd < ve) {
                i64 k = (ve - vd - 1) / vf;
                ans += 1LL * (vd + vd + k * vf) * (k + 1) / 2;
            }
        } else {
            if (vd > ve) {
                i64 k = (vd - ve - 1) / -vf;
                ans += 1LL * (vd + vd + k * vf) * (k + 1) / 2;
            }
        }
    }
    
    std::cout << ans << "\n";
    
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

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

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: 31ms
memory: 3600kb

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: 9ms
memory: 3592kb

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: 42ms
memory: 3532kb

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