QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656300 | #9255. Python Program | Fiatiustitia# | WA | 4ms | 3584kb | C++20 | 3.2kb | 2024-10-19 12:16:34 | 2024-10-19 12:16:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int VAR = 1e9;
void solve()
{
int64_t res = 0;
int64_t a[3] = {0};
{
string s;
cin >> s;
res = stoll(s.substr(4));
}
{
string s;
for (int i = 0; i < 3; i++)
cin >> s;
cin >> s;
s.pop_back();
s.pop_back();
s = s.substr(6);
s.push_back(',');
int tot = 0;
int64_t cur = 0, neg = 0;
for (auto ch : s)
{
if (ch == ',')
{
if (neg)
cur = -cur;
a[tot++] = cur;
neg = 0;
cur = 0;
continue;
}
if (ch == '-')
{
neg = 1;
continue;
}
cur = cur * 10 + (ch - '0');
}
}
int64_t b[3] = {0};
{
string s;
for (int i = 0; i < 3; i++)
cin >> s;
cin >> s;
s.pop_back();
s.pop_back();
s = s.substr(6);
s.push_back(',');
int tot = 0;
int64_t cur = 0, neg = 0;
for (auto ch : s)
{
if (ch == ',')
{
if (neg)
cur = -cur;
b[tot++] = cur;
neg = 0;
cur = 0;
continue;
}
if (ch == '-')
{
neg = 1;
continue;
}
if (isdigit(ch))
cur = cur * 10 + (ch - '0');
else
cur = VAR;
}
}
if (!a[2])
a[2] = 1;
if (!b[2])
b[2] = 1;
auto work = [&](int64_t a, int64_t b, int64_t c) -> int64_t
{
if (c > 0)
{
auto len = (b - a) / c + 1;
while (len > 0 && a + (len - 1) * c >= b)
len--;
return (a + a + (len - 1) * c) * len / 2;
}
else
{
auto len = (a - b) / -c + 1;
while (len > 0 && a + (len - 1) * c <= b)
len--;
return (a + a + (len - 1) * c) * len / 2;
}
return -1;
};
if (a[2] > 0)
{
for (int64_t i = a[0]; i < a[1]; i += a[2])
{
auto [p, q, r] = b;
if (p == VAR)
p = i;
if (q == VAR)
q = i;
if (r == VAR)
r = i;
res += work(p, q, r);
}
}
else
{
for (int64_t i = a[0]; i > a[1]; i += a[2])
{
auto [p, q, r] = b;
if (p == VAR)
p = i;
if (q == VAR)
q = i;
if (r == VAR)
r = i;
res += work(p, q, r);
}
}
cout << res << '\n';
}
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
auto _ = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
#ifdef LOCAL
cerr << clock() - _ << '\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
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: 3584kb
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: 4ms
memory: 3476kb
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: 1ms
memory: 3520kb
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: -100
Wrong Answer
time: 4ms
memory: 3524kb
input:
ans=0 for i in range(1,1000000): for j in range(i,114514,-1): ans+=j print(ans)
output:
160109900981627037
result:
wrong answer 1st lines differ - expected: '160610445975856765', found: '160109900981627037'