QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628149#9255. Python Programnjupt_zy#WA 6ms3804kbC++172.5kb2024-10-10 18:54:312024-10-10 18:54:31

Judging History

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

  • [2024-10-10 18:54:31]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3804kb
  • [2024-10-10 18:54:31]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<string>
#include<regex>
#define VAR 23333333333LL
using namespace std;
string s1,s2;
vector<long long> m;
void pre()
{
     regex num_reg(R"(\-?\d+)");
     auto w1begin=sregex_iterator(s1.begin(),s1.end(),num_reg);
     auto w1end=sregex_iterator();
     for (sregex_iterator i=w1begin;i!=w1end;++i)
          {
          string num=i->str();
          m.push_back(stoll(num));
          }
     if (m.size()<3) m.push_back(1); //第三个参数被省略,缺省值为1

     string ch;
     ch+=s1[4]; //out loop varible

     s2=s2.substr(s2.find('('));
     regex inner_reg("["+ch+"]|\\-?\\d+");
     w1begin=sregex_iterator(s2.begin(),s2.end(),inner_reg);
     w1end=sregex_iterator();
     for (sregex_iterator i=w1begin;i!=w1end;++i)
          {
          string num=i->str();
          if (num!=ch) m.push_back(stoll(num)); //此处是外层循环变量,标记VAR
               else m.push_back(VAR);
          }
     if (m.size()<6) m.push_back(1); //第三个参数被省略,缺省值为1
}
int main()
{
     
     //freopen("1.py","r",stdin);
     //freopen("output.out","w",stdout);
     ios::sync_with_stdio(false);
     //cin.tie(nullptr);
     getline(cin,s1);
     getline(cin,s1);
     getline(cin,s2);
     pre();
     long long a=m[0],b=m[1],c=m[2],d=m[3],e=m[4],f=m[5],i,j;
     auto update=[](long long &d,long long &e,long long &f,const long long &i){
          if (m[3]==VAR) d=i;
          if (m[4]==VAR) e=i;
          if (m[5]==VAR) f=i;
     };
     auto calc=[](const long long d,const long long e,const long long f) -> long long {
          if (f>0 && d>=e) return 0;
          if (f<0 && d<=e) return 0;
          long long n=(e-1-d)/f,last;
          if (f>0)
               {
               if (d+n*f<e) last=d+n*f;
                    else last=d+(n-1)*f;
               }
          else
               {
               if (d+n*f>e) last=d+n*f;
                    else last=d+(n-1)*f;
               }
          n=(last-d)/f+1;
          return (d+last)*n/2;
     };
     long long ans=0;
     if (c>0)
          {
          for (i=a;i<b;i+=c)
               {
               update(d,e,f,i);
               ans+=calc(d,e,f);
               }
          }
     else
          {
          for (i=a;i>b;i+=c)
               {
               update(d,e,f,i);
               ans+=calc(d,e,f);
               //cout<<ans<<"\n";
               }
          }
     cout<<ans<<"\n";
     return 0;
}

詳細信息

Test #1:

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

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

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: 6ms
memory: 3804kb

input:

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

output:

166666666666499999

result:

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