QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577971 | #9255. Python Program | cuongson# | WA | 5ms | 3812kb | C++14 | 6.1kb | 2024-09-20 15:44:47 | 2024-09-20 15:44:50 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
string str, str1, str2, str3;
int a, b, c, d, e, f;
long long ans;
int main()
{
a = b = c = d = e = f = -1e7;
cin >> str;
cin >> str;
cin >> str1;
cin >> str >> str;
int cnt = 0;
int flag = 1;
for(int i = 6; i < str.size() - 1; i ++)
{
int num = 0;
flag = 1;
if(str[i] == '-') flag = -1;
else num = str[i] - '0';
int j = i + 1;
while(j < str.size() && str[j] >= '0' && str[j] <= '9')
{
num = num * 10 + (str[j] - '0');
++ j;
}
num *= flag;
if(cnt == 0) a = num;
else if(cnt == 1) b = num;
else if(cnt == 2) c = num;
++ cnt;
i = j;
}
cin >> str >> str2 >> str >> str;
cnt = 0;
for(int i = 6; i < str.size() - 1; i ++)
{
if(i < str.size() && str[i] >= 'a' && str[i] <= 'z')
{
while(i < str.size() && str[i] >= 'a' && str[i] <= 'z')
{
str3 = str3 + str[i];
++ i;
}
++ cnt;
continue;
}
int num = 0;
flag = 1;
if(str[i] == '-') flag = -1;
else num = str[i] - '0';
int j = i + 1;
if(j < str.size() && str[j] >= '0' && str[j] <= '9')
{
while(j < str.size() && str[j] >= '0' && str[j] <= '9')
{
num = num * 10 + (str[j] - '0');
++ j;
}
}
num *= flag;
if(cnt == 0) d = num;
else if(cnt == 1) e = num;
else if(cnt == 2) f = num;
++ cnt;
i = j;
}
cin >> str >> str;
cnt = 0;
if(c == -1e7) c = 1;
if(c >= 1 && b > a) cnt = (b - 1 - a) / c + 1;
else if(c < 0 && a > b) cnt = (a - 1 - b) / (-c) + 1;
if(d == -1e7 || e == -1e7 || f == -1e7)
{
if(c >= 1)
{
for(int i = a; i < b; i += c)
{
if(d == -1e7)
{
if(f >= 1 && e > i)
{
int k = (e - 1 - i) / f + 1;
int s = i + (k - 1) * f;
ans += 1ll * (i + s) * k / 2;
}
else if(f < 0 && i > e)
{
int k = (i - 1 - e) / (-f) + 1;
int s = i + (k - 1) * f;
ans += 1ll * (i + s) * k / 2;
}
}
else if(e == -1e7)
{
if(f >= 1 && i > d)
{
int k = (i - 1 - d) / f + 1;
int s = d + (k - 1) * f;
ans += 1ll * (d + s) * k / 2;
}
else if(f < 0 && i < d)
{
int k = (d - 1 - i) / (-f) + 1;
int s = d + (k - 1) * f;
ans += 1ll * (d + s) * k / 2;
}
}
else
{
if(i >= 1 && d < e)
{
int k = (e - 1 - d) / i + 1;
int s = d + (k - 1) * i;
ans += 1ll * (d + s) * k / 2;
}
else if(i < 0 && d > e)
{
int k = (d - 1 - e) / (-i) + 1;
int s = d + (k - 1) * i;
ans += 1ll * (d + s) * k / 2;
}
}
}
}
else
{
for(int i = a; i > b; i += c)
{
if(d == -1e7)
{
if(f >= 1 && e > i)
{
int k = (e - 1 - i) / f + 1;
int s = i + (k - 1) * f;
ans += 1ll * (i + s) * k / 2;
}
else if(f < 0 && i > e)
{
int k = (i - 1 - e) / (-f) + 1;
int s = i + (k - 1) * f;
ans += 1ll * (i + s) * k / 2;
}
}
else if(e == -1e7)
{
if(f >= 1 && i > d)
{
int k = (i - 1 - d) / f + 1;
int s = d + (k - 1) * f;
ans += 1ll * (d + s) * k / 2;
}
else if(f < 0 && i < d)
{
int k = (d - 1 - i) / (-f) + 1;
int s = d + (k - 1) * f;
ans += 1ll * (d + s) * k / 2;
}
}
else
{
if(i >= 1 && d < e)
{
int k = (e - 1 - d) / i + 1;
int s = d + (k - 1) * i;
ans += 1ll * (d + s) * k / 2;
}
else if(i < 0 && d > e)
{
int k = (d - 1 - e) / (-i) + 1;
int s = d + (k - 1) * i;
ans += 1ll * (d + s) * k / 2;
}
}
}
}
}
else
{
if(f >= 1 && e > d)
{
int k = (e - 1 - d) / f + 1;
int s = d + (k - 1) * f;
ans += 1ll * cnt * (d + s) * k / 2;
}
else if(f < 0 && e < d)
{
int k = (d - 1 - e) / (-f) + 1;
int s = d + (k - 1) * f;
ans += 1ll * cnt * (d + s) * k / 2;
}
}
/*
ans=0
for q in range(10,3,-3):
for i in range(0,100,17):
ans+=i
print(ans)
int res = 0;
for(int i = 10; i > 3; i -= 3)
for(int j = 0; j < 100; j += 17)
res+=j;
cout << res << ' ' << cnt << endl;
*/
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 3736kb
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: 3812kb
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: -100
Wrong Answer
time: 1ms
memory: 3808kb
input:
ans=0 for i in range(31,321983,2): for j in range(313,382193): ans+=j print(ans)
output:
337436856749
result:
wrong answer 1st lines differ - expected: '11756963404587200', found: '337436856749'