QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627385#9255. Python Programcabbagea#AC ✓4ms3852kbC++173.5kb2024-10-10 15:46:512024-10-10 15:46:51

Judging History

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

  • [2024-10-10 15:46:51]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3852kb
  • [2024-10-10 15:46:51]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

const int N = 1e6 + 5;

bool flag[4] = {0};
int flagAns, det;

int find(string& s, int index, char c) {
    for (int i = index; i < s.size(); i++) {
        if (s[i] == c)
            return i;
    }
    return -1;
}

void solve() {
    int a = 0, b = 0, c = 1, d = 0, e = 0, f = 1;
    char p, q;
    string s;
    cin >> s >> s >> p >> s >> s;
    int cnt = count(s.begin(), s.end(), ',');
    int idx1 = find(s, 0, ',');
    a = stoi(s.substr(6, idx1 - 6));
    if (cnt == 2) {
        int idx2 = find(s, idx1 + 1, ',');
        b = stoi(s.substr(idx1 + 1, idx2 - idx1 - 1));
        int idx3 = find(s, idx2 + 1, ')');
        c = stoi(s.substr(idx2 + 1, idx3 - idx2 - 1));
    }
    else {
        int idx2 = find(s, idx1, ')');
        b = stoi(s.substr(idx1 + 1, idx2 - idx1 - 1));
    }

    cin >> s >> q >> s >> s;
    cnt = count(s.begin(), s.end(), ',');
    idx1 = find(s, 0, ',');
    if (!isdigit(s[idx1 - 1]))
        flag[1] = true;
    else
        d = stoi(s.substr(6, idx1 - 6));
    if (cnt == 2) {
        int idx2 = find(s, idx1 + 1, ',');
        if (!isdigit(s[idx2 - 1]))
            flag[2] = true;
        else
            e = stoi(s.substr(idx1 + 1, idx2 - idx1 - 1));
        int idx3 = find(s, idx2 + 1, ')');
        if (!isdigit(s[idx3 - 1]))
            flag[3] = true;
        else
            f = stoi(s.substr(idx2 + 1, idx3 - idx2 - 1));
    }
    else {
        int idx2 = find(s, idx1 + 1, ')');
        if (!isdigit(s[idx2 - 1]))
            flag[2] = true;
        else
            e = stoi(s.substr(idx1 + 1, idx2 - idx1 - 1));
    }
    cin >> s;
    if (s[s.size() - 1] == p)
        flagAns = 1;
    else if (s[s.size() - 1] == q)
        flagAns = 2;
    else
        det = stoi(s.substr(5, s.size()));
    cin >> s;

    //cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << " " << p << " " << q << endl;
    //cout << flag[1] << " " << flag[2] << " " << flag[3] << " " << flagAns << endl;
    //cout << det << endl;

    int ans = 0;
    if (a < b)
        for (int i = a; i < b; i += c) {
            int te = e, td = d, tf = f;
            if (flag[1])
                td = i;
            if (flag[2])
                te = i;
            if (flag[3])
                tf = i;
            int t = max(0ll, (te - td + tf + (tf > 0 ? -1 : 1)) / tf);
            //cout << ans << " " << te << " " << td << " " << tf << endl;
            if (flagAns == 1)
                ans += t * i;
            else if (flagAns == 2)
                ans += (2 * td + (t - 1) * tf) * t / 2;
            else
                ans += t * det;
        }
    else
        for (int i = a; i > b; i += c) {
            int te = e, td = d, tf = f;
            if (flag[1])
                td = i;
            if (flag[2])
                te = i;
            if (flag[3])
                tf = i;
            int t = max(0ll, (te - td + tf + (tf > 0 ? -1 : 1)) / tf);
            if (flagAns == 1)
                ans += t * i;
            else if (flagAns == 2)
                ans += (2 * td + (t - 1) * tf) * t / 2;
            else
                ans += t * det;
            //cout << ans << " " << te << " " << td << " " << tf << endl;
        }
    cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

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

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

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

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

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