QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688711#9255. Python Programreal_sigma_team#AC ✓3ms3812kbC++232.3kb2024-10-30 12:52:472024-10-30 12:52:47

Judging History

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

  • [2024-10-30 12:52:47]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3812kb
  • [2024-10-30 12:52:47]
  • 提交

answer

#include <bits/stdc++.h>

int64_t calc(int d, int e, int f) {
	int64_t res = 0;
	if (f > 0) {
		e--;
		if (e < d) return 0;
		int64_t qq = (e - d) / f;
		return (2 * d + f * qq) * (qq + 1) / 2;
	} else {
		e++;
		f = -f;
		if (e > d) return 0;
		int64_t qq = (d - e) / f;
		return (2 * d - f * qq) * (qq + 1) / 2;
	}
}

int32_t main() {
	std::cin.tie(nullptr)->sync_with_stdio(false);

	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
	std::string s;
	std::getline(std::cin, s);
	std::getline(std::cin, s);
	int pos = s.find("range(");
	pos += 6;
	while (s[pos] != ',' && s[pos] != ')') {
		a *= 10;
		a += s[pos] - '0';
		pos++;
	}
	pos++;
	while (s[pos] != ',' && s[pos] != ')') {
		b *= 10;
		b += s[pos] - '0';
		pos++;
	}
	if (s[pos] == ')') {
		c = 1;
	} else {
		pos++;
		bool minus = false;
		if (s[pos] == '-') minus = true, pos++;
		while (s[pos] != ',' && s[pos] != ')') {
			c *= 10;
			c += s[pos] - '0';
			pos++;
		}
		if (minus) c *= -1;
	}
	std::getline(std::cin, s);
	pos = s.find("range(");
	pos += 6;
	if ('0' <= s[pos]&& s[pos] <= '9') {
		while (s[pos] != ',' && s[pos] != ')') {
			d *= 10;
			d += s[pos] - '0';
			pos++;
		}
	} else {
		d = -228;
		pos++;
	}
	pos++;
	if ('0' <= s[pos] && s[pos] <= '9') {
		while (s[pos] != ',' && s[pos] != ')') {
			e *= 10;
			e += s[pos] - '0';
			pos++;
		}
	} else {
		e = -228;
		pos++;
	}
	if (s[pos] == ')') {
		f = 1;
	} else {
		pos++;
		if (s[pos] == '-' || ('0' <= s[pos] && s[pos] <= '9')) {
			bool minus = false;
			if (s[pos] == '-') minus = true, pos++;
			while (s[pos] != ',' && s[pos] != ')') {
				f *= 10;
				f += s[pos] - '0';
				pos++;
			}
			if (minus) f *= -1;
		} else {
			f = -228;
		}
	}
	// std::cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << std::endl;
	int64_t ans = 0;
	if (c > 0) {
		for (int i = a; i < b; i += c) {
			// std::cout << i << ' ' << calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f) << std::endl;
			ans += calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f);
		}
	} else {
		for (int i = a; i > b; i += c) {
			// std::cout << i << ' ' << calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f) << std::endl;
			ans += calc(d == -228 ? i : d, e == -228 ? i : e, f == -228 ? i : f);
		}
	}
	std::cout << ans;
}

详细

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

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

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

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

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