QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#570696#9288. Roman Palindromeseggegg185WA 0ms3952kbC++14913b2024-09-17 17:09:512024-09-17 17:09:55

Judging History

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

  • [2024-09-17 17:09:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3952kb
  • [2024-09-17 17:09:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n,dp[100010],x[100010],stk[100010][2],top = 0; char s[100010];
int main() {
	scanf("%d%s",&n,s+1); dp[0] = 0;
	for(int i = 1; i <= n; i++) {
		dp[i] = dp[i-1]+1; x[i] = 1;
		if(i >= 2) {
			if(s[i] == s[i-1] && (s[i]=='M'||s[i]=='C'||s[i]=='X'||s[i]=='I')) {
				if(dp[i-2]+1 < dp[i]) x[i] = 2,dp[i] = dp[i-2]+1; 
			}
		}
		if(i >= 3) {
			bool ok = false;
			ok |= (s[i-2]=='M'&&s[i-1]=='C'&&s[i]=='M');
			ok |= (s[i-2]=='C'&&s[i-1]=='X'&&s[i]=='C');
			ok |= (s[i-2]=='X'&&s[i-1]=='I'&&s[i]=='X');
			if(ok) {
				if(dp[i-3]+1 < dp[i]) x[i] = 3,dp[i] = dp[i-3]+1; 
			}
		}
	}
	int cur = n;
	while(cur) {
		stk[++top][0] = cur; stk[top][1] = x[cur];
		cur -= x[cur];
	}
	printf("%d\n",top);
	for(int i = top; i >= 1; i--) {
		for(int j = stk[i][0]-stk[i][1]+1; j <= stk[i][0]; j++) putchar(s[j]); putchar('\n');
	}
	return 0;
}

詳細信息

Test #1:

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

input:

5
MMXXI

output:

3
MM
XX
I

result:

ok OK!

Test #2:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

1
I

output:

1
I

result:

ok OK!

Test #3:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

1
V

output:

1
V

result:

ok OK!

Test #4:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

1
X

output:

1
X

result:

ok OK!

Test #5:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

1
L

output:

1
L

result:

ok OK!

Test #6:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

1
C

output:

1
C

result:

ok OK!

Test #7:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

1
D

output:

1
D

result:

ok OK!

Test #8:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

1
M

output:

1
M

result:

ok OK!

Test #9:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

2
XX

output:

1
XX

result:

ok OK!

Test #10:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

2
LL

output:

2
L
L

result:

ok OK!

Test #11:

score: -100
Wrong Answer
time: 0ms
memory: 3880kb

input:

3
XXX

output:

2
XX
X

result:

wrong answer Jury is better: 1 vs 2