QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685399#9255. Python Programucup-team5351WA 2ms4092kbC++142.8kb2024-10-28 19:15:542024-10-28 19:15:54

Judging History

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

  • [2024-10-28 19:15:54]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4092kb
  • [2024-10-28 19:15:54]
  • 提交

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 coef1=1,coef2=1;
        if(c<0)a=-a,b=-b,c=-c,coef1*=-1;
        if(f<0)d=-d,e=-e,f=-f,coef2*=-1;
        auto calc=[&](int l,int r,int k)->ll{
            if(l>=r)return 0;
            int c=(r-l-1)/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?coef1*i:d,e==inf?coef1*i:e,f==inf?coef1*i:f);
        printf("%lld\n",coef2*ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: -100
Wrong Answer
time: 2ms
memory: 3752kb

input:

ans=0
for i in range(1,1000000):
    for j in range(i,1,-1):
        ans+=j
print(ans)

output:

11757719601212769

result:

wrong answer 1st lines differ - expected: '166666666665500001', found: '11757719601212769'