QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#745938#9255. Python Programgz_zgAC ✓3ms3936kbC++142.3kb2024-11-14 12:32:132024-11-14 12:32:14

Judging History

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

  • [2024-11-14 12:32:14]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3936kb
  • [2024-11-14 12:32:13]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define ft first
#define sd second
#define cn cout<<"NO"<<endl
#define cy cout<<"YES"<<endl
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define mii map<int,int>
#define pii pair<int,int>
#define debug(x) cerr<<#x<<"="<<x<<endl
#define debug2(x,y) cerr<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define all(v) v.begin(),v.end()
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7; 

int a=-1,b=-1,c=1;
int D=-1,E=-1,F=1;
int *d=&D, *e=&E, *f=&F;

void solve()
{
    string s; getline(cin,s);
    getline(cin,s);
    for(int i=0;i<s.size();i++)    
    {
        if('0'<=s[i] && s[i]<='9')
        {
            int j=i;
            while(j+1<s.size() && '0'<=s[j+1] && s[j+1]<='9')j++;
            int num=0;
            for(int k=i;k<=j;k++)num=num*10+s[k]-'0';
            if(s[i-1]=='-')num=-num;
            if(a==-1)a=num;
            else if(b==-1)b=num;
            else c=num;            
            i=j;
        }
    }
    char ch=s[4];

    getline(cin,s); s=s.substr(4);
    char x[10]{},y[10]{},z[10]{};
    sscanf(s.c_str(),"%*[\tf]or %*c in range(%[^,)],%[^,)],%[^,)]):",x,y,z);
    if(z[0]=='\0')z[0]='1';

    int loopa=666;
    if(x[0]==ch)d=&loopa;
    else *d=stoi(x);
    if(y[0]==ch)e=&loopa;
    else *e=stoi(y);
    if(z[0]==ch)f=&loopa;
    else *f=stoi(z);

    if((b-a)*c<=0)cout<<0<<endl;
    else
    {
        if(a<b)
        {
            int ans=0;
            for(loopa=a;loopa<=b-1;loopa+=c)
            {   
                if((*e-*d)*(*f)<=0)continue;
                int cnt=(abs((*e) - (*d)) - 1) / abs(*f)+1;
                int sum=((*d) + (*d) + (cnt-1) * (*f)) * cnt / 2;
                ans+=sum;
            }
            cout<<ans<<endl;    
        }
        else
        {
            int ans=0;
            for(loopa=a;loopa>=b+1;loopa+=c)
            {   
                if((*e-*d)*(*f)<=0)continue;
                int cnt=(abs((*e) - (*d)) - 1) / abs(*f)+1;
                int sum=((*d) + (*d) + (cnt-1) * (*f)) * cnt / 2;
                ans+=sum;
            }
            cout<<ans<<endl;  
        }   
    }   
}

signed main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
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: 3608kb

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

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

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

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