QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637883 | #9255. Python Program | XiaoMo247# | AC ✓ | 6ms | 3856kb | C++14 | 11.1kb | 2024-10-13 14:18:26 | 2024-10-13 14:18:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const ll MAXN = 2e5 + 5;
ll ans = 0;
string s, a, b, c1, c2;
ll calc1(ll a1, ll mx, ll d){
mx --;
if(a1 > mx) return 0;
ll xs = (mx - a1) / d + 1;
ll an = a1 + (xs - 1) * d;
ll ret = (a1 + an) * xs / 2;
return ret;
}
ll calc2(ll a1, ll mn, ll d){
mn ++;
if(a1 < mn) return 0;
ll xs = (mn - a1) / d + 1;
ll an = a1 + (xs - 1) * d;
ll ret = (a1 + an) * xs / 2;
return ret;
}
signed main(){
// freopen("in.in", "r", stdin);
ios::sync_with_stdio(false);
cin >> s;
cin >> s >> a >> s >> c1;
cin >> s >> b >> s >> c2;
cin >> s;
cin >> s;
int v1 = 0, v2 = 0, idx1[5], idx2[5];
for(int i = 0; i < c1.size(); i ++){
if(c1[i] == ','){
v1 ++;
idx1[v1] = i;
}
}
for(int i = 0; i < c2.size(); i ++){
if(c2[i] == ','){
v2 ++;
idx2[v2] = i;
}
}
if(v1 == 1){
ll st1 = stoll(c1.substr(6, idx1[1] - 6));
ll ed1 = stoll(c1.substr(idx1[1] + 1, ((ll)c1.size() - 2) - idx1[1]));
if(st1 >= ed1){
cout << 0 << "\n";
return 0;
}
ll cz1 = ed1 - st1;
if(v2 == 1){
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
ll ans = 0;
for(int i = st1; i < ed1; i ++){
if(i > (ed2 - 1)) continue;
ans += (i + ed2 - 1) * (ed2 - i) / 2;
}
cout << ans << "\n";
return 0;
}
if(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll ans = 0;
for(int i = st1; i < ed1; i ++){
if(st2 > i) continue;
ans += (st2 + i) * (i - st2 + 1) / 2;
}
cout << ans << "\n";
return 0;
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
if(st2 >= ed2){
cout << 0 << "\n";
return 0;
}
ll cz2 = (st2 + ed2 - 1) * (ed2 - st2) / 2;
cout << cz1 * cz2 << "\n";
}
else{
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1));
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc2 < 0){
for(int i = st1; i < ed1; i ++){
ans += calc2(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
else{
for(int i = st1; i < ed1; i ++){
ans += calc1(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
}
if(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc2 < 0){
for(int i = st1; i < ed1; i ++){
ans += calc2(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
else{
for(int i = st1; i < ed1; i ++){
ans += calc1(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1));
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll cz2 = 0;
if(st2 >= ed2 && bc2 > 0){
cout << 0 << "\n";
return 0;
}
if(st2 <= ed2 && bc2 < 0){
cout << 0 << "\n";
return 0;
}
if(bc2 < 0){
for(int i = st2; i > ed2; i += bc2){
cz2 += i;
}
}
else{
for(int i = st2; i < ed2; i += bc2){
cz2 += i;
}
}
cout << cz1 * cz2 << "\n";
}
}
else{
ll st1 = stoll(c1.substr(6, idx1[1] - 6));
ll ed1 = stoll(c1.substr(idx1[1] + 1, idx1[2] - idx1[1] - 1));
ll bc1 = stoll(c1.substr(idx1[2] + 1, ((ll)c1.size() - 2) - idx1[2]));
ll cz1 = 0;
if(st1 >= ed1 && bc1 > 0){
cout << 0 << "\n";
return 0;
}
if(st1 <= ed1 && bc1 < 0){
cout << 0 << "\n";
return 0;
}
if(bc1 < 0){
for(int i = st1; i > ed1; i += bc1){
cz1 ++;
}
}
else{
for(int i = st1; i < ed1; i += bc1){
cz1 ++;
}
}
if(v2 == 1){
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
ll ans = 0;
if(bc1 < 0){
for(int i = st1; i > ed1; i += bc1){
if(i > (ed2 - 1)) continue;
ans += (i + ed2 - 1) * (ed2 - i) / 2;
}
}
else{
for(int i = st1; i < ed1; i += bc1){
if(i > (ed2 - 1)) continue;
ans += (i + ed2 - 1) * (ed2 - i) / 2;
}
}
cout << ans << "\n";
return 0;
}
if(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll ans = 0;
if(bc1 < 0){
for(int i = st1; i > ed1; i += bc1){
if(st2 > i) continue;
ans += (st2 + i) * (i - st2 + 1) / 2;
}
}
else{
for(int i = st1; i < ed1; i += bc1){
if(st2 > i) continue;
ans += (st2 + i) * (i - st2 + 1) / 2;
}
}
cout << ans << "\n";
return 0;
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
if(st2 >= ed2){
cout << 0 << "\n";
return 0;
}
ll cz2 = (st2 + ed2 - 1) * (ed2 - st2) / 2;
cout << cz1 * cz2 << "\n";
}
else{
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1));
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc1 < 0){
if (bc2 < 0) {
for (int i = st1; i > ed1; i += bc1) {
ans += calc2(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
} else {
for (int i = st1; i > ed1; i += bc1) {
ans += calc1(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
}
else{
if (bc2 < 0) {
for (int i = st1; i < ed1; i += bc1) {
ans += calc2(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
else {
for (int i = st1; i < ed1; i += bc1) {
ans += calc1(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
}
}
if(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc1 < 0){
if (bc2 < 0) {
for (int i = st1; i > ed1; i += bc1) {
ans += calc2(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
else {
for (int i = st1; i > ed1; i += bc1) {
ans += calc1(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
}
else{
if (bc2 < 0) {
for (int i = st1; i < ed1; i += bc1) {
ans += calc2(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
else {
for (int i = st1; i < ed1; i += bc1) {
ans += calc1(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
}
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1));
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll cz2 = 0;
if(st2 >= ed2 && bc2 > 0){
cout << 0 << "\n";
return 0;
}
if(st2 <= ed2 && bc2 < 0){
cout << 0 << "\n";
return 0;
}
if(bc2 < 0){
for(int i = st2; i > ed2; i += bc2){
cz2 += i;
}
}
else{
for(int i = st2; i < ed2; i += bc2){
cz2 += i;
}
}
cout << cz1 * cz2 << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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: 3620kb
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: 6ms
memory: 3856kb
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: 0ms
memory: 3604kb
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: 6ms
memory: 3600kb
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