QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#552880#9255. Python Programucup-team1134#AC ✓3ms3824kbC++233.4kb2024-09-08 03:39:022024-09-08 03:39:03

Judging History

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

  • [2024-09-08 03:39:03]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3824kb
  • [2024-09-08 03:39:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<string> S(5);
    for(int q=0;q<5;q++){
        getline(cin,S[q]);
    }
    
    char i=S[1][4];
    
    vector<int> A,B;
    int now=0;
    bool minus=false;
    for(int x=15;x<si(S[1]);x++){
        if(S[1][x]==','||S[1][x]==')'){
            if(minus) now=-now;
            A.push_back(now);
            now=0;
            minus=false;
        }else if(S[1][x]=='-'){
            minus=true;
        }else{
            now*=10;
            now+=(S[1][x]-'0');
        }
    }
    
    now=0;
    for(int x=19;x<si(S[2]);x++){
        if(S[2][x]==','||S[2][x]==')'){
            if(minus) now=-now;
            B.push_back(now);
            now=0;
            minus=false;
        }else if(S[2][x]==i){
            now=INF;
        }else if(S[2][x]=='-'){
            minus=true;
        }else{
            now*=10;
            now+=(S[2][x]-'0');
        }
    }
    
    if(si(A)<3) A.push_back(1);
    if(si(B)<3) B.push_back(1);
    
    ll ans=0;
    
    if(A[2]>0){
        for(ll s=A[0];s<A[1];s+=A[2]){
            ll st;
            if(B[0]==INF) st=s;
            else st=B[0];
            
            ll en;
            if(B[1]==INF) en=s;
            else en=B[1];
            
            ll dif;
            if(B[2]==INF) dif=s;
            else dif=B[2];
            
            if(dif>0){
                if(st<en){
                    ll can=(en-st-1)/dif;
                    ans+=(st+(st+dif*can))*(can+1)/2;
                }
            }else{
                if(st>en){
                    ll can=(st-en-1)/(-dif);
                    ans+=(st+(st+dif*can))*(can+1)/2;
                }
            }
        }
    }else{
        for(ll s=A[0];s>A[1];s+=A[2]){
            ll st;
            if(B[0]==INF) st=s;
            else st=B[0];
            
            ll en;
            if(B[1]==INF) en=s;
            else en=B[1];
            
            ll dif;
            if(B[2]==INF) dif=s;
            else dif=B[2];
            
            if(dif>0){
                if(st<en){
                    ll can=(en-st-1)/dif;
                    ans+=(st+(st+dif*can))*(can+1)/2;
                }
            }else{
                if(st>en){
                    ll can=(st-en-1)/(-dif);
                    ans+=(st+(st+dif*can))*(can+1)/2;
                }
            }
        }
    }
    
    cout<<ans<<endl;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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