QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#686300#9255. Python Programucup-team5351AC ✓3ms4096kbC++142.8kb2024-10-29 10:52:142024-10-29 10:52:16

Judging History

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

  • [2024-10-29 10:52:16]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:4096kb
  • [2024-10-29 10:52:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#define ALL(v) v.begin(),v.end()
#define For(i,_) for(int i=0,i##end=_;i<i##end;++i) // [0,_)
#define FOR(i,_,__) for(int i=_,i##end=__;i<i##end;++i) // [_,__)
#define Rep(i,_) for(int i=(_)-1;i>=0;--i) // [0,_)
#define REP(i,_,__) for(int i=(__)-1,i##end=_;i>=i##end;--i) // [_,__)
typedef long long ll;
typedef unsigned long long ull;
#define V vector
#define pb push_back
#define pf push_front
#define qb pop_back
#define qf pop_front
#define eb emplace_back
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
#define fi first
#define se second
const int dir[4][2]={{-1,0},{0,1},{1,0},{0,-1}},inf=0x3f3f3f3f,mod=1e9+7;
const ll infl=0x3f3f3f3f3f3f3f3fll;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
int init=[](){return cin.tie(nullptr)->sync_with_stdio(false),0;}();
int main(){
    int t_case=1;
    //scanf("%d",&t_case);
    while(t_case--){
        string s;
        V<char>t(30);
        For(_,5)cin>>s;
        sscanf(s.c_str(),"range(%[^)]",t.data());
        int a,b,c;
        if(count(ALL(t),',')==1){
            sscanf(t.data(),"%d,%d",&a,&b),c=1;
        }
        else if(count(ALL(t),',')==2){
            sscanf(t.data(),"%d,%d,%d",&a,&b,&c);
        }
        else assert(0);
        For(_,4)cin>>s;
        sscanf(s.c_str(),"range(%[^)]",t.data());
        int d,e,f;
        if(count(ALL(t),',')==1){
            For(i,t.size())if(islower(t[i])){
                if(i&&t[i-1]==',')sscanf(t.data(),"%d,%*[a-z]",&d),e=inf;
                else d=inf,sscanf(t.data(),"%*[a-z],%d",&e);
                goto skip1;
            }
            sscanf(t.data(),"%d,%d",&d,&e);
            skip1:;
            f=1;
        }
        else if(count(ALL(t),',')==2){
            For(i,t.size())if(islower(t[i])){
                if(i&&t[i-1]==','&&i+1<t.size()&&t[i+1]==',')sscanf(t.data(),"%d,%*[a-z],%d",&d,&f),e=inf;
                else if(i&&t[i-1]==',')sscanf(t.data(),"%d,%d,%*[a-z]",&d,&e),f=inf;
                else d=inf,sscanf(t.data(),"%*[a-z],%d,%d",&e,&f);
                goto skip2;
            }
            sscanf(t.data(),"%d,%d,%d",&d,&e,&f);
            skip2:;
        }
        else assert(0);
        int coef=1;
        if(c<0)a=-a,b=-b,c=-c,coef*=-1;
        auto calc=[&](int l,int r,int k)->ll{
            int x=(k>0?r-l:l-r);
            if(x<1)return 0;
            int c=(x-1)/abs(k)+1;
            return 1ll*c*l+1ll*c*(c-1)/2*k;
        };
        ll ans=0;
        for(int i=a;i<b;i+=c)ans+=calc(d==inf?coef*i:d,e==inf?coef*i:e,f==inf?coef*i:f);
        printf("%lld\n",ans);
    }
    return 0;
}

詳細信息

Test #1:

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

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

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

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

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

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