QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556102#9255. Python ProgramRepeater#AC ✓3ms3828kbC++202.3kb2024-09-10 15:03:322024-09-10 15:03:32

Judging History

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

  • [2024-09-10 15:03:32]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3828kb
  • [2024-09-10 15:03:32]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int INF = 1000000000;

constexpr int N = 100;

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	std::string useless;
	std::cin >> useless;
	std::cin >> useless;

	char val1; std::cin >> val1;

	std::cin >> useless;
	std::cin >> useless;

	std::string range1 = useless.substr(6);
	range1.pop_back(); 
	range1.pop_back();
	range1 += ",";

	std::cin >> useless;

	char val2; std::cin >> val2;
	std::cin >> useless;
	std::cin >> useless;
	std::string range2 = useless.substr(6);
	range2.pop_back();
	range2.pop_back();
	range2 += ",";

	std::cin >> useless;
	std::cin >> useless;

	int l = 0, r = 0, d = 0, tmp = 0;
	int pos = 0, type = 1;
	for(int i = 0; i < (int)range1.size(); i++)
	{
		char c = range1[i];
		if(c == '-')
		{
			type = -1;
			continue;
		}
		if(c == ',') 
		{
			if(pos == 0) l = type * tmp;
			else if(pos == 1) r = type * tmp;
			else d = type * tmp;
			tmp = 0;
			pos++;
			type = 1;
			continue;
		}

		tmp = tmp * 10 + (c - '0');
	}	
	if(d == 0) d = 1;

	// std::cerr << l << " " << r << " " << d << "\n";

	int l2 = 0, r2 = 0, d2 = 0, tmp2 = 0;
	int pos2 = 0, type2 = 1;
	for(int i = 0; i < (int)range2.size(); i++)
	{
		char c = range2[i];
		if('a' <= c && c <= 'z')
		{
			tmp2 = INF;
			continue;
		}
		if(c == '-')
		{
			type2 = -1;
			continue;
		}
		if(c == ',') 
		{
			if(pos2 == 0) l2 = type2 * tmp2;
			else if(pos2 == 1) r2 = type2 * tmp2;
			else d2 = type2 * tmp2;
			tmp2 = 0;
			pos2++;
			type2 = 1;
			continue;
		}

		tmp2 = tmp2 * 10 + (c - '0');
	}	
	if(d2 == 0) d2 = 1;

	// std::cerr << l2 << " " << r2 << " " << d2 << "\n";

	i64 ans = 0;
	if(d > 0) r--;
	else r++;
	for(int i = l; (d > 0 ? i <= r : i >= r); i += d)
	{
		int tl = (l2 == INF) ? i : l2;
		int tr = (r2 == INF) ? i : r2;
		int td = (d2 == INF) ? i : d2;

		if(td > 0) tr--;
		else tr++;

		if(td > 0 && tl > tr) continue;
		if(td < 0 && tl < tr) continue;

		if(td > 0) ans += 1LL * (tl + tl + (tr - tl) / td * td) * ((tr - tl) / td + 1) / 2;
		else ans += 1LL * (tl + tl + (tl - tr) / (-td) * td) * ((tl - tr) / (-td) + 1) / 2;
		// std::cerr << ans << "\n";
	}

	std::cout << ans << "\n";

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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