QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692590#9255. Python ProgramWaO_o#AC ✓31ms3608kbC++202.7kb2024-10-31 14:45:222024-10-31 14:45:23

Judging History

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

  • [2024-10-31 14:45:23]
  • 评测
  • 测评结果:AC
  • 用时:31ms
  • 内存:3608kb
  • [2024-10-31 14:45:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define deg( x ) cout<<""#x"="<<x<<endl
#define endl '\n'
#define pll pair<int,int>
#define se second
#define fr first

const int N=1e5+10;

struct node{
    string a ;
    string st , en , ad;
};

node get( string s ){
    //cout<<s<<endl;

    string a;

    int i=0;

    while( s[ i ]==' ' ) i++;

    i+=4;

    while( s[ i ]!=' ' ){
        a+=s[ i ];
        i++;
    }

    while( s[ i ]!='(' ) i++;

    i++;

    string st;
    while( s[ i ]!=',' ){
        st+=s[ i ];
        i++;
    }

    i++;

    string en;
    while( s[ i ]!=')' && s[ i ]!=',' ){
        en+=s[ i ];
        i++;
    }

    string ad="1";

    if( s[ i ]==',' ){
        i++;

        ad.clear();

        while( s[ i ]!=')' ){
            ad+=s[ i ];
            i++;
        }
    }

    return { a , st , en , ad };
}

int toint( string s ){

    int f=1;
    int re=0;

    for( auto x:s ){
        re*=10;
        if( x=='-' ) f=-1;
        else re+=x-'0';
    }
    return re*f;
}

int huo( int st , int en , int ad ){
    //cout<<st<<" "<<en<<endl;
    int re=0;

    if( st > en && ad > 0 ) return 0;
    if( st < en && ad < 0 ) return 0;

    int k=( en-st )/ad;

    int mo=st+k*ad;

    int o=mo+st;
    o*=( k+1 );
    o/=2;

    //cout<<o<<endl;

    return o;
}

void solve(){
    string s;
    getline( cin , s );

    int ans=0;
    getline( cin , s );
    node a=get( s );

    getline( cin , s );
    node b=get( s );

    int add=toint( a.ad );
    if( add > 0 ) {
        for (int i = toint(a.st); i < toint(a.en); i += toint(a.ad)) {
            int st, en, ad;
            if (b.st == a.a) st = i;
            else st = toint(b.st);

            if (b.en == a.a) en = i;
            else en = toint(b.en);

            if (b.ad == a.a) ad = i;
            else ad = toint(b.ad);

            ans += huo(st, en+( ad>0?-1:1 ), ad);
        }
    }
    else{
        for (int i = toint(a.st); i > toint(a.en); i += toint(a.ad)) {
            int st, en, ad;
            if (b.st == a.a) st = i;
            else st = toint(b.st);

            if (b.en == a.a) en = i;
            else en = toint(b.en);

            if (b.ad == a.a) ad = i;
            else ad = toint(b.ad);

            ans += huo(st, en+( ad>0?-1:1 ), ad);
        }
    }

    //cout<<a.a<<" "<<a.st<<" "<<a.en<<" "<<a.ad<<endl;
    //cout<<b.a<<" "<<b.st<<" "<<b.en<<" "<<b.ad<<endl;
    cout<<ans<<endl;
}

signed main() {
    //ios::sync_with_stdio( 0 );
    //cout.tie( 0 ); cin.tie( 0 );

    int T=1;
    //cin>>T;

    while( T-- ){
        solve();
    }

    return 0;
}

详细

Test #1:

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

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

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

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: 6ms
memory: 3536kb

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: 31ms
memory: 3536kb

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