QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550701#9255. Python Programucup-team3584#WA 6ms3796kbC++203.4kb2024-09-07 13:56:412024-09-07 13:56:41

Judging History

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

  • [2024-09-07 13:56:41]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3796kb
  • [2024-09-07 13:56:41]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string op;
    getline(cin, op);
    getline(cin, op);
    const ll inf = 1e18;
    char i1, i2, i3;
    ll a, b, c, d, e, f;
    auto read = [&](int &i, ll &x) -> void {
        bool minus = false;
        if (op[i] == '-') minus = true, i += 1;
        if (isdigit(op[i])) {
            x = 0;
            while (isdigit(op[i])) {
                x = x * 10 + op[i] - '0';
                i += 1;
            }
            if (minus) x = -x;
        } else {
            x = inf;
            i += 1;
        }
    };
    i1 = op[4];
    for (int i = 0; i < op.size(); ++i) {
        if (op.substr(i, 5) == "range") {
            i += 6;
            read(i, a);
            if (op[i] == ',') {
                i += 1;
                read(i, b);
                if (op[i] == ',') {
                    i += 1;
                    read(i, c);
                } else {
                    c = 1;
                }
            }
            break;
        }
    }
    getline(cin, op);
    i2 = op[8];
    for (int i = 0; i < op.size(); ++i) {
        if (op.substr(i, 5) == "range") {
            i += 6;
            read(i, d);
            if (op[i] == ',') {
                i += 1;
                read(i, e);
                if (op[i] == ',') {
                    i += 1;
                    read(i, f);
                } else {
                    c = 1;
                }
            }
            break;
        }
    }
    getline(cin, op);
    for (int i = 0; i < op.size(); ++i) {
        if (op[i] == '=') i3 = op[i + 1];
    }
    ll ans = 0;
    if (c > 0) {
        for (ll i = a; i < b; i += c) {
            ll D = (d == inf ? i : d);
            ll E = (e == inf ? i : e);
            ll F = (f == inf ? i : f);
            if (F > 0) {
                ll cnt = 0;
                if (D < E) cnt = (E - D - 1) / F + 1;
                if (i1 == i3) ans += cnt * i;
                else {
                    ans += (D + D + (cnt - 1) * F) * cnt / 2;
                }
            } else {
                ll cnt = 0;
                if (D > E) cnt = (D - E - 1) / abs(F) + 1;
                if (i1 == i3) ans += cnt * i;
                else {
                    ans += (D + D + (cnt - 1) * F) * cnt / 2;
                }
            }
        }
    } else {
        for (int i = a; i > b; i += c) {
            ll D = (d == inf ? i : d);
            ll E = (e == inf ? i : e);
            ll F = (f == inf ? i : f);
            if (F > 0) {
                ll cnt = 0;
                if (D < E) cnt = (E - D - 1) / F + 1;
                if (i1 == i3) ans += cnt * i;
                else {
                    ans += (D + D + (cnt - 1) * F) * cnt / 2;
                }
            } else {
                ll cnt = 0;
                if (D > E) cnt = (D - E - 1) / abs(F) + 1;
                if (i1 == i3) ans += cnt * i;
                else {
                    ans += (D + D + (cnt - 1) * F) * cnt / 2;
                }
            }
        }
    }
    cout << ans << endl;
}

详细

Test #1:

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

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

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

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: -100
Wrong Answer
time: 2ms
memory: 3560kb

input:

ans=0
for i in range(31,321983,2):
    for j in range(313,382193):
        ans+=j
print(ans)

output:

904360551174144

result:

wrong answer 1st lines differ - expected: '11756963404587200', found: '904360551174144'