QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#746002#9255. Python Programgz_zgAC ✓4ms3952kbC++141.9kb2024-11-14 12:55:022024-11-14 12:55:02

Judging History

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

  • [2024-11-14 12:55:02]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3952kb
  • [2024-11-14 12:55:02]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

int a=-1,b=-1,c=1;
int dd=-1,ee=-1,ff=1;
int *d=&dd, *e=&ee, *f=&ff;

void solve()
{
    string s; getline(cin,s);//getline(cin,s)可以读取一整行,遇到<换行符>结束,并将输入流中的<换行符>删除

    getline(cin,s); char ch=s[4];
    char A[10]{},B[10]{},C[10]{};
    sscanf(s.c_str(),"%*[\tf]or %*c in range(%[^,)],%[^,)],%[^,)]):",A,B,C);
    if(C[0]=='\0')C[0]='1';
    a=stoi(A); b=stoi(B); c=stoi(C);//stoi不仅适用于 <string> 还适用于 <字符数组>

    getline(cin,s); s=s.substr(4);//s=s.substr(4)将s中的前4个空格字符删除,方便后续的<sscanf>
    char D[10]{},E[10]{},F[10]{};
    sscanf(s.c_str(),"%*[\tf]or %*c in range(%[^,)],%[^,)],%[^,)]):",D,E,F);
    if(F[0]=='\0')F[0]='1';

    int loop=666;
    if(D[0]==ch)d=&loop;
    else *d=stoi(D);
    if(E[0]==ch)e=&loop;
    else *e=stoi(E);
    if(F[0]==ch)f=&loop;
    else *f=stoi(F);

    if((b-a)*c<=0)cout<<0<<endl;
    else
    {
        if(a<b)
        {
            int ans=0;
            for(loop=a;loop<=b-1;loop+=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(loop=a;loop>=b+1;loop+=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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3692kb

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: 1ms
memory: 3952kb

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

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

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

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