QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#606972#9255. Python Programpropane#AC ✓46ms3876kbC++202.0kb2024-10-03 13:21:172024-10-03 13:21:17

Judging History

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

  • [2024-10-03 13:21:17]
  • 评测
  • 测评结果:AC
  • 用时:46ms
  • 内存:3876kb
  • [2024-10-03 13:21:17]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

vector<string> split(string s){
    int pos = 0;
    size_t nxt;
    vector<string> ans;
    while((nxt = s.find(',', pos)) != string::npos){
        ans.push_back(s.substr(pos, nxt - pos));
        pos = nxt + 1;
    }
    ans.push_back(s.substr(pos));
    return ans;
}

LL get(LL a, LL b, LL c){
    if (c > 0){
        b -= 1;
        if (a > b) return 0;
        b = a + (b - a) / c * c;
        return (a + b) * ((b - a) / c + 1) / 2;
    }
    else{
        b += 1;
        if (a < b) return 0;
        b = a - (a - b) / (-c) * (-c);
        return (a + b) * ((a - b) / (-c) + 1) / 2;
    }
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    string s;
    getline(cin, s);
    getline(cin, s);
    int pos = s.find('(');
    s = s.substr(pos + 1);
    s.pop_back();
    s.pop_back();
    auto v1 = split(s);
    if (v1.size() == 2) v1.push_back("1");
    int a = stoi(v1[0]);
    int b = stoi(v1[1]);
    int c = stoi(v1[2]);
    getline(cin, s);
    pos = s.find('(');
    s = s.substr(pos + 1);
    s.pop_back();
    s.pop_back();
    auto v2 = split(s);
    if (v2.size() == 2) v2.push_back("1");
    LL ans = 0;
    if (c > 0){
        for(int i = a; i < b; i += c){
            auto f = [&](string s){
                if (isalpha(s[0])){
                    return i;
                }
                return stoi(s);
            };

            ans += get(f(v2[0]), f(v2[1]), f(v2[2]));
        }
    }
    else{
        for(int i = a; i > b; i += c){
            auto f = [&](string s){
                if (isalpha(s[0])){
                    return i;
                }
                return stoi(s);
            };
            ans += get(f(v2[0]), f(v2[1]), f(v2[2]));
        }
    }
    cout << ans << '\n';

}

详细

Test #1:

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

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

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

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

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

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