QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718464#9255. Python Programyld#AC ✓3ms3828kbC++203.3kb2024-11-06 20:35:102024-11-06 20:35:10

Judging History

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

  • [2024-11-06 20:35:10]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3828kb
  • [2024-11-06 20:35:10]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int inf=1e18;
void solve()
{
    string tmp;
    char x,y;
    int a=0,b=0,c=0,d=0,e=0,f=0;
    string r1,r2;
    for(int i=1;i<=5;i++)
    {
        if(i==2)
        {
            cin>>tmp>>x>>tmp>>tmp;
            int l=tmp.find('('),r=tmp.find(')');
            tmp=tmp.substr(l,r-l+1);
            r1=tmp;
        }
        else if(i==3)
        {
            cin>>tmp>>y>>tmp>>tmp;
            int l=tmp.find('('),r=tmp.find(')');
            tmp=tmp.substr(l,r-l+1);
            r2=tmp;
        }
        else cin>>tmp;
    }
    // cout<<x<<' '<<y<<endl;
    int num=0,ch=1;
    for(int i=1;i<r1.size();i++)
    {
        if(r1[i]=='-') ch=-1;
        if(isdigit(r1[i])) num=num*10+r1[i]-'0';
        else if(num!=0)
        {
            if(a==0) a=ch*num;
            else if(b==0) b=ch*num;
            else c=ch*num;
            num=0,ch=1;
        }
    }
    if(c==0) c=1;
    num=0,ch=1;
    int cnt=0;
    for(int i=1;i<r2.size();i++)
    {
        if(r2[i]=='-') ch=-1;
        if(isdigit(r2[i])) num=num*10+r2[i]-'0';
        else
        {
            if(r2[i]==x)
            {
                if(cnt==0) d=inf;
                if(cnt==1) e=inf;
                if(cnt==2) f=inf;
                cnt++;
            }
            else if(num!=0)
            {
                if(cnt==0) d=ch*num;
                if(cnt==1) e=ch*num;
                if(cnt==2) f=ch*num;
                num=0,ch=1;
                cnt++;
            }
        }
    }
    if(f==0) f=1;
    int ans=0;
    // cerr<<a<<' '<<b<<' '<<c<<endl;
    // cerr<<d<<' '<<e<<' '<<f<<endl;
    if(c<0)
    {
        // swap(a,b),c=-c;
        for(int i=a;i>b;i+=c)
        {
            int l,r,step;
            if(d==inf) l=i;
            else l=d;
            if(e==inf) r=i;
            else r=e;
            if(f==inf) step=i;
            else step=f;
            // cout<<l<<' '<<r<<' '<<step<<endl;
            if(step>0)
            {
                if(l>=r) continue;
                int num=(r-l-1)/step+1;
                ans+=(l+(num-1)*step+l)*num/2;
            }
            else
            {
                if(l<=r) continue;
                int num=(l-r-1)/abs(step)+1;
                // cerr<<num<<endl;
                ans+=(l+(num-1)*step+l)*num/2;
            }
            // cout<<ans<<endl;
        }
    }
    else
    {
        for(int i=a;i<b;i+=c)
        {
            int l,r,step;
            if(d==inf) l=i;
            else l=d;
            if(e==inf) r=i;
            else r=e;
            if(f==inf) step=i;
            else step=f;
            // cout<<l<<' '<<r<<' '<<step<<endl;
            if(step>0)
            {
                if(l>=r) continue;
                int num=(r-l-1)/step+1;
                ans+=(l+(num-1)*step+l)*num/2;
            }
            else
            {
                if(l<=r) continue;
                int num=(l-r-1)/abs(step)+1;
                // cerr<<num<<endl;
                ans+=(l+(num-1)*step+l)*num/2;
            }
            // cout<<ans<<endl;
        }
    }
    cout<<ans<<endl;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    while(t--) solve();
    return 0;
}

详细

Test #1:

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

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

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

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

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