QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691940#9255. Python ProgramCore_65536#AC ✓4ms3612kbC++203.2kb2024-10-31 13:30:002024-10-31 13:30:03

Judging History

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

  • [2024-10-31 13:30:03]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3612kb
  • [2024-10-31 13:30:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'


int sw(char x){
    int t=x-'0';
    return t;
}
ll fx(ll a,ll b,ll c)
{
    if(c>0){
        if(b<=a){
            return 0;
        }
    }else{
        if(b>=a){
            return 0;
        }
    }
    // cout<<a<<" "<<b<<" "<<c<<endl;
    if(a>b)
    {
        // 5 1 -2
        // 5 4 3 2

        ll k=(a-(b+1))/(-c);
        ll head=a;
        ll ed=a-k*(-c);
        return (head+ed)*(k+1)/2;
        // int k=a-b;
        // int t=k/(-c);
        // return (a+a+(t-1)*c)*(-c)/2;
    }
    else if(a<b)
    {
        ll k=(b-1-a)/c;
        ll head=a;
        ll ed=a+k*c;
        return (head+ed)*(k+1)/2;
    }
    return 0;

}
void solve()
{
    string s;
    cin>>s;
    cin>>s;
    string a;
    cin>>a;
    cin>>s;
    string range1;
    cin>>range1;
    int arg[4];
    memset(arg,0,sizeof(arg));
    for(int i=6,j=0;i<range1.size();i++){
        if(range1[i]==')'){
            break;
        }
        if(range1[i]==','){
            j++;
            continue;
        }
        if(range1[i]=='-'){
            i++;
            arg[j]=-sw(range1[i]);
            continue;
        }
        arg[j]=arg[j]*10+sw(range1[i]);
    }
    if(arg[2]==0){
        arg[2]=1;
    }
    cin>>s;
    cin>>s;
    cin>>s;
    string range2;
    cin>>range2;
    int brg[4];
    memset(brg,0,sizeof(brg));
    vector<int > vis(4,0);
    for(int i=6,j=0;i<range2.size();i++){
        if(range2[i]==')'){
            break;
        }
        if(range2[i]==','){
            j++;
            continue;
        }
        if(range2[i]==a[0]){
            vis[j]=1;
            continue;
        }
        if(range2[i]=='-'){
            i++;
            brg[j]=-sw(range2[i]);
            continue;
        }
        brg[j]=brg[j]*10+sw(range2[i]);
    }
    if(brg[2]==0){
        brg[2]=1;
    }
    cin>>s;
    cin>>s;
    // for(int i=0;i<3;i++){
    //     cout<<arg[i]<<" ";
    // }
    // cout<<endl;
    // for(int i=0;i<3;i++){
    //     cout<<brg[i]<<" ";
    // }
    // cout<<endl;
    ll ans=0;
    if(arg[1]>=arg[0]){
        for(int i=arg[0];i<arg[1];i+=arg[2]){
            int d,e,f;
            d=brg[0];
            e=brg[1];
            f=brg[2];
            if(vis[0]==1){
                d=i;
            }
            if(vis[1]==1){
                e=i;
            }
            if(vis[2]==1){
                f=i;
            }
            ans+=fx(d,e,f);
        }
    }else{
        for(int i=arg[0];i>arg[1];i+=arg[2]){
                int d,e,f;
            d=brg[0];
            e=brg[1];
            f=brg[2];
            if(vis[0]==1){
                d=i;
            }
            if(vis[1]==1){
                e=i;
            }
            if(vis[2]==1){
                f=i;
            }
            ans+=fx(d,e,f);
            // cout<<d<<" "<<e<<" "<<f<<"\n";
        }
    }
    cout<<ans<<"\n";
}

int 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: 3612kb

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

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

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

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

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