QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#550761#9255. Python Programucup-team3877#AC ✓4ms3824kbC++202.1kb2024-09-07 14:12:542024-09-07 14:12:55

Judging History

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

  • [2024-09-07 14:12:55]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3824kb
  • [2024-09-07 14:12:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
constexpr ll INFLL = (1LL << 62), MOD = 998244353;
constexpr int INF = (1 << 30);

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll ans = 0;
    //2
    rep(i,4) cin >> s;
    int x = 0, y = 0;
    while(s[6+x]!=',') ++x;
    ll a, b, c = 1, d = -1, e = -1, f = 1;
    a = stoi(s.substr(6,x));
    ++x;
    while(s[6+x+y]!=',' && s[6+x+y]!=')') ++y;
    b = stoi(s.substr(6+x,y));
    if(s[6+x+y]==','){
        x += y+1;
        y = 0;
        while(s[6+x+y]!=')') ++y;
        c = stoi(s.substr(6+x,y));
    }
    //3
    rep(i,4) cin >> s;
    bool cd = false, ce = false, cf = false;
    x = 0, y = 0;
    if('a'<=s[6] && s[6]<='z') cd = true, x += 1;
    else{
        while(s[6+x]!=',') ++x;
        d = stoi(s.substr(6,x));
    }
    ++x;
    if('a'<=s[6+x] && s[6+x]<='z') ce = true, x += 1;
    else{
        while(s[6+x+y]!=',' && s[6+x+y]!=')') ++y;
        e = stoi(s.substr(6+x,y));
    }
    if(s[6+x+y]==','){
        x += y+1, y = 0;
        if('a'<=s[6+x] && s[6+x]<='z') cf = true, x += 1;
        else{
            while(s[6+x+y]!=')') ++y;
            f = stoi(s.substr(6+x,y));
        }
    }

    if(c>0){
        for(;a<b;a+=c){
            ll p = (cd?a:d), q = (ce?a:e), r = (cf?a:f), z = 1;
            if(r<0) p *= -1, q *= -1, r *= -1, z = -1;
            ll t = max<ll>(0, (q-p+r-1)/r);
            ans += z * (p+p+r*(t-1))*t/2;
        }
    }else{
        for(;a>b;a+=c){
            ll p = (cd?a:d), q = (ce?a:e), r = (cf?a:f), z = 1;
            if(r<0) p *= -1, q *= -1, r *= -1, z = -1;
            ll t = max<ll>(0, (q-p+r-1)/r);
            ans += z * (p+p+r*(t-1))*t/2;
        }
    }
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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