QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562236#9255. Python ProgramMysterious_CatAC ✓4ms3704kbC++141.7kb2024-09-13 15:56:552024-09-13 15:56:56

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 15:56:56]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3704kb
  • [2024-09-13 15:56:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int a, b, c, d, e, f;
long long ans;
string str[5];

int getsgn(int v) {
	if (v > 0) {
		return 1;
	} else if (v == 0) {
		return 0;
	} else {
		return -1;
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	for (int i = 0; i < 5; i++) {
		getline(cin, str[i]);
	}

	char I = str[1][4];
	bool sgn = 0;
	int *now = &a;
	for (char x : str[1]) {
		if (x >= '0' && x <= '9') {
			*now = *now * 10 + x - '0';
		} else if (x == '-') {
			sgn = 1;
		} else if (x == ',') {
			now = now == &a ? &b : &c;
		}
	}
	if (c == 0) {
		c = 1;
	} else if (sgn) {
		c = -c;
	}

	sgn = 0;
	now = &d;
	bool ok = 0;
	for (char x : str[2]) {
		if (x == '(') {
			ok = 1;
		}
		if (!ok) {
			continue;
		}
		if (x >= '0' && x <= '9') {
			*now = *now * 10 + x - '0';
		} else if (x == '-') {
			sgn = 1;
		} else if (x == ',') {
			now = now == &d ? &e : &f;
		} else if (x == I) {
			*now = 1e9;
		}
	}
	if (f == 0) {
		f = 1;
	} else if (sgn) {
		f = -f;
	}

	if (c > 0) {
		for (int i = a; i < b; i += c) {
			int l = d == 1e9 ? i : d;
			int r = e == 1e9 ? i : e;
			int v = f == 1e9 ? i : f;
			if (getsgn(r - l) != getsgn(v)) {
				continue;
			}
			int t = (abs(r - l) + abs(v) - 1) / abs(v);
			ans += 1ll * (l + l + 1ll * (t - 1) * v) * t / 2;
		}
	} else {
		for (int i = a; i > b; i += c) {
			int l = d == 1e9 ? i : d;
			int r = e == 1e9 ? i : e;
			int v = f == 1e9 ? i : f;
			if (getsgn(r - l) != getsgn(v)) {
				continue;
			}
			int t = (abs(r - l) + abs(v) - 1) / abs(v);
			ans += 1ll * (l + l + 1ll * (t - 1) * v) * t / 2;
		}
	}
	cout << ans << '\n';

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3704kb

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: 3648kb

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: 3672kb

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: 3588kb

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: 4ms
memory: 3660kb

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