QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#628029 | #9255. Python Program | njupt_zy# | WA | 1ms | 3952kb | C++17 | 2.2kb | 2024-10-10 18:18:48 | 2024-10-10 18:18:50 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<string>
#include<regex>
#define VAR 23333333
using namespace std;
string s1,s2;
vector<int> 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(stoi(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(stoi(num)); //此处是外层循环变量,标记VAR
else m.push_back(VAR);
}
if (m.size()<6) m.push_back(1); //第三个参数被省略,缺省值为1
}
int main()
{
//freopen("input.in","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();
int a=m[0],b=m[1],c=m[2],d=m[3],e=m[4],f=m[5],i,j;
auto update=[](int &d,int &e,int &f,const int &i){
if (m[3]==VAR) d=i;
if (m[4]==VAR) e=i;
if (m[5]==VAR) f=i;
};
auto calc=[](const int d,const int e,const int 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 (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: 3952kb
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: 3916kb
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: 0ms
memory: 3788kb
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'