QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670993#9255. Python Programsnow_miku#AC ✓7ms3800kbC++232.8kb2024-10-24 09:43:182024-10-24 09:43:18

Judging History

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

  • [2024-10-24 09:43:18]
  • 评测
  • 测评结果:AC
  • 用时:7ms
  • 内存:3800kb
  • [2024-10-24 09:43:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
    string s[5];
    for (int i = 0; i < 5; i++) getline(cin, s[i]);
    //for (int i = 0; i < 5; i++) cout << s[i] << '\n';
    //cout << s[1][15] << '\n';
    int pos = 15, a = 0; bool neg = 0;
    if (s[1][pos] == '-') neg = 1, pos++;
    while (isdigit(s[1][pos])) a = (a << 1) + (a << 3) + s[1][pos] - '0', pos++;
    pos++; a *= (neg ? -1 : 1);

    int b = 0; neg = 0;
    if (s[1][pos] == '-') neg = 1, pos++;
    while (isdigit(s[1][pos])) b = (b << 1) + (b << 3) + s[1][pos] - '0', pos++;
    b *= (neg ? -1 : 1);

    pos++; int c = 0; neg = 0;
    if (s[1][pos] == '-') neg = 1, pos++;
    while (isdigit(s[1][pos])) c = (c << 1) + (c << 3) + s[1][pos] - '0', pos++;
    c *= (neg ? -1 : 1);

    pos = 19; bool dc = 0; int dn = 0;
    if (s[2][pos] <= 'z' && s[2][pos] >= 'a') dc = 1, pos++;
    else {
        neg = 0;
        if (s[2][pos] == '-') neg = 1, pos++;
        while (isdigit(s[2][pos])) dn = (dn << 1) + (dn << 3) + s[2][pos] - '0', pos++;
        dn *= (neg ? -1 : 1);
    } pos++;

    bool ec = 0; int en = 0;
    if (s[2][pos] <= 'z' && s[2][pos] >= 'a') ec = 1, pos++;
    else {
        neg = 0;
        if (s[2][pos] == '-') neg = 1, pos++;
        while (isdigit(s[2][pos])) en = (en << 1) + (en << 3) + s[2][pos] - '0', pos++;
        en *= (neg ? -1 : 1);
    } pos++;
    
    bool fc = 0; int fn = 0;
    if (s[2][pos] <= 'z' && s[2][pos] >= 'a') fc = 1, pos++;
    else {
        neg = 0;
        if (s[2][pos] == '-') neg = 1, pos++;
        while (isdigit(s[2][pos])) fn = (fn << 1) + (fn << 3) + s[2][pos] - '0', pos++;
        fn *= (neg ? -1 : 1);
    } 
    ll ans = 0;
    // cout << a << ' ' << b << ' ' << c << '\n';
    // cout << dc << ' ' << dn << '\n';
    // cout << ec << ' ' << en << '\n';
    // cout << fc << ' ' << fn << '\n';
    if (c == 0) c = 1;
    if (c > 0) {
        for (int i = a; i < b; i += c) {
            int d = (dc ? i : dn), e = (ec ? i : en), f = (fc ? i : fn);
            if (f == 0) f = 1;
            if (f > 0 && d >= e) continue;
            if (f < 0 && d <= e) continue;
            int k = max(0, (int)(ceil(1.0 * (e - d) / f - 1)));
            ans += (ll) (k + 1) * d + (ll) f * (k + 1) * k / 2;
        }
    } else {
        for (int i = a; i > b; i += c) {
            int d = (dc ? i : dn), e = (ec ? i : en), f = (fc ? i : fn);
            if (f == 0) f = 1;
            if (f > 0 && d >= e) continue;
            if (f < 0 && d <= e) continue;
            int k = max(0, (int)(ceil(1.0 * (e - d) / f - 1)));
            ans += (ll) (k + 1) * d + (ll) f * (k + 1) * k / 2;
        }
    }
     cout << ans;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

详细

Test #1:

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

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

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

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

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