QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#717706 | #9255. Python Program | leafmaple# | AC ✓ | 8ms | 3816kb | C++20 | 3.2kb | 2024-11-06 18:45:23 | 2024-11-06 18:45:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main (){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin>>s;
int ans = 0;
cin>>s;
cin>>s;
char i = s[0];
cin>>s;
cin>>s;
//cout<<s<<endl;
int now = 0;
int flag = 0;
vector<string> v1(3) ;
for(int i=0;i<s.size();i++)
{
if(s[i] == '(' )
flag = 1;
else if(s[i] ==')')
{ flag = 0;
break;
}
else if(flag)
{
if(s[i] == ',')
{
now ++;
}
else
{
v1[now] += s[i] ;
}
}
}
now = 0;
cin>>s;
cin>>s;
cin>>s;
cin>>s;
vector<string> v2(3) ;
for(int i=0;i<(int)s.size();i++)
{
if(s[i] == '(' )
flag = 1;
else if(s[i] ==')')
{ flag = 0;
break;
}
else if(flag)
{
if(s[i] == ',')
{
now ++;
}
else
{
v2[now] += s[i];
}
}
}
int a = 0;
int b = 0;
int c = 1;
int sub = 1;
for(auto c:v1[0])
if(c == '-')
sub = -1;
else
a =a*10 + c-'0';
a *= sub ;
sub = 1;
for(auto d:v1[1])
if(d == '-')
sub = -1;
else
b =b*10 + d-'0';
b*=sub ;
sub = 1;
if(v1[2].size())
{
c = 0;
for(auto d:v1[2])
if(d == '-')
sub = -1;
else
c =c*10 + d-'0';
c *= sub ;
}
//cout<<a<<" "<<b<<" "<<c<<endl;
//cout<<i<<endl;
//cout<<a<<" "<<b<<" "<<c<<endl;
//cout<<v2[0]<<" "<<v2[1]<<" "<<v2[2]<<endl;
if(c < 0)
{
for(int l=a;l>b;l+=c)
{
int d = 0;
int e = 0;
int f = 1;
if(v2[0][0] == i )
d = l;
else
{ int sub = 1;
for(auto c:v2[0])
{ if(c == '-')
sub = -1;
else
d = d*10 + c-'0';
}
d *= sub;
}
if(v2[1][0] == i )
e = l;
else
{ int sub = 1;
for(auto c:v2[1])
if(c == '-')
sub = -1;
else
e = e*10 + c-'0';
e *= sub ;
}
if(v2[2].size() == 0)
;
else
{ f = 0;
int sub = 1;
for(auto c: v2[2])
if(c == '-')
sub = -1;
else
f = f*10 + c-'0';
f *= sub ;
}
//cout<<f<<endl;
if(f < 0 )
e ++;
else
e -- ;
if(d*f > e*f)
continue ;
int n = (e - d)/f + 1 ;
//cout<<d<<' '<<e<<" "<<f<<' '<<n<<endl;
e = d + f * (n - 1);
ans += (e + d ) * n / 2;
}
cout<<ans<<endl;
}
else
{
for(int l=a;l<b;l+=c)
{
int d = 0;
int e = 0;
int f = 1;
if(v2[0][0] == i )
d = l;
else
{ int sub = 1;
for(auto c:v2[0])
{ if(c == '-')
sub = -1;
else
d = d*10 + c-'0';
}
d *= sub;
}
if(v2[1][0] == i )
e = l;
else
{ int sub = 1;
for(auto c:v2[1])
if(c == '-')
sub = -1;
else
e = e*10 + c-'0';
e *= sub ;
}
if(v2[2].size() == 0)
;
else
{ f = 0;
int sub = 1;
for(auto c: v2[2])
if(c == '-')
sub = -1;
else
f = f*10 + c-'0';
f *= sub ;
}
//cout<<f<<endl;
if(f < 0 )
e ++;
else
e -- ;
if(d*f > e*f)
continue ;
int n = (e - d)/f + 1 ;
///cout<<d<<' '<<e<<" "<<f<<' '<<n<<endl;
e = d + f * (n - 1);
ans += (e + d ) * n / 2;
}
cout<<ans<<endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3596kb
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: 5ms
memory: 3816kb
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: 2ms
memory: 3612kb
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: 8ms
memory: 3532kb
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