QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#556398 | #9255. Python Program | SLF666# | AC ✓ | 3ms | 3824kb | C++20 | 3.3kb | 2024-09-10 17:38:52 | 2024-09-10 17:38:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
#define endl "\n"
#define ll long long
#define int ll
vector<int> check(string s, char aa){
vector<int>a;
int x = 0;
int flag = 1;
for(int i=6;;i++){
// cout<<s[i]<<endl;
if(s[i] == ')'){
a.push_back(flag * x);
break;
}
else if(s[i] == ','){
a.push_back(flag * x);
flag = 1;
x = 0;
}
else if(s[i] == '-'){
flag = -1;
}
else if(s[i] == aa){
x = inf;
flag = 1;
}
else {
x = x * 10 + (s[i] - '0');
}
}
if(a.size() == 2)a.push_back(1);
return a;
}
void solve(){
ll ans = 0;
vector<string>s(20);
for(int i=1;i<=11;i++)cin>>s[i];
for(int i=4;i<s[1].size();i++){
int x = s[1][i] - '0';
ans = ans * 10 + x;
}
char a = s[3][0], b = s[7][0];
char add = s[10][ s[10].size() - 1 ];
vector<int>opa = check(s[5], a);
vector<int>opb = check(s[9], a);
// cout<<s[5]<<endl;
// for(auto &x:opa)cout<<x<<" ";
// cout<<endl;
// cout<<s[9]<<endl;
// for(auto &x:opb)cout<<x<<" ";
// cout<<endl;
if(opa[2] < 0){
opa[2] *= -1;
swap(opa[0], opa[1]);
opa[0] += 1;
opa[1] += 1;
}
for(int i=opa[0]; i < opa[1];i += opa[2]){
// cout<<"i = "<<i<<endl;
int x = i;
if(opb[0] == inf){//起点取i
if(opb[2] < 0 && x <= opb[1] || opb[2] > 0 && x >= opb[1]){
continue;
}
int l = i, r = opb[1], d = abs(opb[2]);
int cnt = (abs(l - r) + d - 1) / d;
r = i + (cnt - 1) * opb[2];
// cout<<"l = "<<l<<" r = "<<r<<endl;
if(add == b)ans += 1ll * (l + r) * cnt / 2;
else ans += 1ll * cnt * i;
}
else if(opb[1] == inf){//最值取i
x = opb[0];
int l = opb[0], r = i, d = opb[2];
int dd = abs(d);
if(d < 0){
r += 1;
}
else r -= 1;
//[l, r]
// cout<<"L = "<<l<<" R = "<<r<<endl;
if(d < 0 && l < r || d > 0 && l > r)continue;
int cnt = (abs(l - r) + 1 + dd - 1) / dd;
// cout<<"cnt = "<<cnt<<endl;
r = l + (cnt - 1) * d;
// cout<<"l = "<<l<<" r = "<<r<<endl;
if(add == b)ans += 1ll * (l + r) * cnt / 2;
else ans += 1ll * cnt * i;
}
else if(opb[2] == inf){//d为i
int l = opb[0], r = opb[1], d = i;
r -= 1;
if(l > r)continue;
int cnt = (r - l + 1 + d - 1) / d;
r = l + (cnt - 1) * d;
if(add == b)ans += 1ll * (l + r) * cnt / 2;
else ans += 1ll * cnt * i;
}
else {
int l = opb[0], r = opb[1], d = opb[2];
int dd = abs(d);
if(d < 0){
r += 1;
}
else r -= 1;
if(d < 0 && l < r || d > 0 && l > r)continue;
// cout<<"yrs\n";
int cnt = (abs(l - r) + dd) / dd;
r = l + (cnt - 1) * d;
// cout<<"l = "<<l<<" r = "<<r<<" cnt = "<<cnt<<endl;
if(add == b)ans += 1ll * (l + r) * cnt / 2;
else ans += 1ll * cnt * i;
}
}
cout<<ans<<endl;
}
/*
ans=0
for q in range(10,100):
for i in range(99,100,1):
ans+=q
print(ans)
*/
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin>>t;
for(int i=1;i<=t;i++){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 3824kb
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: 3ms
memory: 3784kb
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: 3616kb
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: 3ms
memory: 3592kb
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