QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#707063 | #9255. Python Program | Okuchiri# | AC ✓ | 4ms | 3692kb | C++20 | 3.2kb | 2024-11-03 14:32:40 | 2024-11-03 14:32:43 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define For(i, a, n) for(int i = a; i <= n; i++)
#define sz(a) (int)(a.size())
using namespace std;
const int maxn = 1e5 + 5;
ll ans, cnt;
string s;
char a, b, d;
bool ok, fu;
vector<ll> u, v;
void work()
{
ans = 0;
ok = false;
fu = false;
getline(cin, s);
getline(cin, s);
a = s[4];
for(auto x:s)
{
if(x == '(') ok = true;
else if(ok)
{
if(x == ',' || x == ')')
{
u.push_back((fu ? -1ll * cnt : cnt));
cnt = 0;
fu = false;
}
else if(x == '-') fu = true;
else if(x >= '0' && x <= '9')
{
cnt *= 10ll;
cnt += (ll)(x - '0');
}
}
}
if(sz(u) < 3) u.push_back(1);
getline(cin, s);
b = s[8];
ok = false;
for(auto x:s)
{
if(x == '(') ok = true;
else if(ok)
{
if(x == ',' || x == ')')
{
v.push_back((fu ? -1ll * cnt : cnt));
cnt = 0;
fu = false;
}
else if(x == '-') fu = true;
else if(x >= '0' && x <= '9')
{
cnt *= 10ll;
cnt += (ll)(x - '0');
}
else cnt = inf;
}
}
if(sz(v) < 3) v.push_back(1);
getline(cin, s);
d = s[13];
getline(cin, s);
if(u[2] > 0)
{
for(ll i = u[0]; i < u[1]; i += u[2])
{
ll x = v[0];
ll y = v[1];
ll z = v[2];
if(x == inf) x = i;
if(y == inf) y = i;
if(z == inf) z = i;
ll num = 0;
if(z > 0)
{
if(x < y) num = (((y - x) - 1ll) / z) + 1ll;
}
else if(z < 0)
{
if(x > y) num = (((x - y) - 1ll) / (z * -1ll)) + 1ll;
}
if(d == a)
{
ans += i * num;
}
else if(d == b)
{
ans += (x + x + z * (num - 1ll)) * num / 2ll;
}
}
}
else{
for(ll i = u[0]; i > u[1]; i += u[2])
{
ll x = v[0];
ll y = v[1];
ll z = v[2];
if(x == inf) x = i;
if(y == inf) y = i;
if(z == inf) z = i;
ll num = 0;
if(z > 0)
{
if(x < y) num = (((y - x) - 1ll) / z) + 1ll;
}
else if(z < 0)
{
if(x > y) num = (((x - y) - 1ll) / (z * -1ll)) + 1ll;
}
if(d == a)
{
ans += i * num;
}
else if(d == b)
{
ans += (x + x + z * (num - 1ll)) * num / 2ll;
}
}
}
cout << ans << "\n";
return;
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T=1;
//cin>>T;
while(T--)
{
work();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3692kb
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: 3628kb
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: 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: 0ms
memory: 3640kb
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