QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578682#9255. Python ProgramGenesis#TL 0ms3848kbC++143.9kb2024-09-20 20:48:122024-09-20 20:48:16

Judging History

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

  • [2024-09-20 20:48:16]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3848kb
  • [2024-09-20 20:48:12]
  • 提交

answer

#include<iostream>
#include<string>

typedef long long ll;
using namespace std;
string  s;
ll ans;
int st = -1;
int rnt = -1;
int cnt1 = 0, cnt2 = 0;
int h1[8], h2[8];
char diyi, dier;
int GetNum(string s) {
	int x = 0;
	int len = s.length();
	int m = 0;
	if (s[0] == '-') {
		m = 1;
	}
	for (int i = m; i < len; i++) {
		x += (s[i] - '0');
		if (i != len - 1)x *= 10;
	}
	if (m)x = -x;
	return x;
}
string getString(string x, int i, int j) {
	string h;
	for (int z = i; z <= j; z++) {
		h.push_back(x[z]);
	}
	return h;

}
void getkuohao1(string s) {
	int len = s.length();
	int j = 6;
	for (int i = 6; i < len; i++) {
		if (s[i] == ',') {
			cnt1++;
			string x = s.substr(j, i - j);
			//cout << x << "----" << endl;
			h1[cnt1] = GetNum(x);
			if (i + 1 < len)j = i + 1;
		}
		if (s[i] == ')') {
			cnt1++;
			string x = s.substr(j, i - j);
			h1[cnt1] = GetNum(x);
		}
	}

	if (cnt1 == 6) {
		cnt1++;
		h1[cnt1] = 1;
	}
}
void getkuohao2(string s) {
	int len = s.length();
	int j = 6;
	for (int i = 6; i < len; i++) {
		if (s[i] == ',') {
			cnt2++;
			string x = s.substr(j, i - j);
			if (x[0] == diyi) {
				h2[cnt2] = 0x3f3f3f3f;
			}
			//cout << x << "----" << endl;
			else 
			h2[cnt2] = GetNum(x);
			if (i + 1 < len)j = i + 1;
		}
		if (s[i] == ')') {
			cnt2++;
			string x = s.substr(j, i - j);

			if (x[0] == diyi) { 
			h2[cnt2] = 0x3f3f3f3f;
			}
			else 
			h2[cnt2] = GetNum(x);
		}
	}

	if (cnt2 == 6) {
		cnt2++;
		h2[cnt2] = 1;
	}
}
int main() {
	while (cin >> s && s!="print(ans)") {
		if (s == "for" && st == -1) {
			st = 0;
			cnt1++;
			continue;
		}
		else if (st == 0) {
			if (cnt1 == 1) {
				diyi= s[0], cnt1++;
			}
			else if (s == "in") {
				cnt1++;
				continue;
			}
			else if (s[0] == 'r' && s[1] == 'a' && s[2] == 'n') {
				cnt1++;
				getkuohao1(s);
				continue;
			}
		}

		if (s == "for" && st == 0&& cnt1==7) {
			st = 1;
			cnt2++;
			continue;
		}
		else if (st == 1) {
			if (cnt2 == 1) {
				dier = s[0], cnt2++;
			}
			else if (s == "in") {
				cnt2++;
				continue;
			}
			else if (s[0] == 'r' && s[1] == 'a' && s[2] == 'n') {
				cnt2++;
				getkuohao2(s);
				continue;
			}
		}

	}
//	cout << h1[5] << " " << h1[6] << " " << h1[7] << endl;
//	cout << h2[5] << " " << h2[6] << " " << h2[7] << endl;
	if (h1[7] > 0) {
		for (int i = h1[5]; i < h1[6]; i += h1[7]) {
			if (h2[5] == 0x3f3f3f3f) {
				if (h2[7] > 0)
					for (int j = i; j < h2[6]; j += h2[7])ans += j;
				else
					for (int j = i; j > h2[6]; j += h2[7])ans += j;
			}
			else if (h2[6] == 0x3f3f3f3f) {
				if (h2[7] > 0)
					for (int j = h2[5]; j < i; j += h2[7])ans += j;
				else
					for (int j = h2[5]; j > i; j += h2[7])ans += j;
			}
			else if (h2[7] == 0x3f3f3f3f) {
				if (i > 0)
					for (int j = h2[5]; j < h2[6]; j += i)ans += j;
				else
					for (int j = h2[5]; j > h2[6]; j += i)ans += j;
			}
			else {
				if (h2[7] > 0)
					for (int j = h2[5]; j < h2[6]; j += h2[7])ans += j;
				else
					for (int j = h2[5]; j > h2[6]; j += h2[7])ans += j;
			}

		}
	}
	else {
		for (int i = h1[5]; i > h1[6]; i += h1[7]) {
			if (h2[5] == 0x3f3f3f3f) {
				if (h2[7] > 0)
					for (int j = i; j < h2[6]; j += h2[7])ans += j;
				else
					for (int j = i; j > h2[6]; j += h2[7])ans += j;
			}
			else if (h2[6] == 0x3f3f3f3f) {
				if (h2[7] > 0)
					for (int j = h2[5]; j < i; j += h2[7])ans += j;
				else
					for (int j = h2[5]; j > i; j += h2[7])ans += j;
			}
			else if (h2[7] == 0x3f3f3f3f) {
				if (i > 0)
					for (int j = h2[5]; j < h2[6]; j += i)ans += j;
				else
					for (int j = h2[5]; j > h2[6]; j += i)ans += j;
			}
			else {
				if (h2[7] > 0)
					for (int j = h2[5]; j < h2[6]; j += h2[7])ans += j;
				else
					for (int j = h2[5]; j > h2[6]; j += h2[7])ans += j;
			}

		}

	}
	cout << ans << endl;

}

详细

Test #1:

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

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

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: -100
Time Limit Exceeded

input:

ans=0
for i in range(1,1000000):
    for j in range(i,1,-1):
        ans+=j
print(ans)

output:


result: