QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607602#2428. Comma SprinklerLJY_ljyWA 57ms21080kbC++111.8kb2024-10-03 15:30:162024-10-03 15:30:16

Judging History

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

  • [2024-10-03 15:30:16]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:21080kb
  • [2024-10-03 15:30:16]
  • 提交

answer

//Trie树(字典树)练习 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;

const int MAXN = 1000010;
char str[MAXN], Ans[MAXN];
int exist[MAXN], End[MAXN], len, Bound[MAXN];
int eid, cnt, nex[MAXN][30], Type[MAXN];

// 空格 0, 句号 1,逗号 2
int main() {
	while (scanf("%s", str + 1) != EOF) {
		int n = strlen(str + 1), m;
		cnt++;
		if ('a' <= str[n] && str[n] <= 'z') m = n;
		else m = n - 1;
		Type[cnt] = (Type[cnt - 1] % 3) * 3;
		if ('.' == str[n]) Type[cnt] ++;
		if (',' == str[n]) Type[cnt] += 2; 
		for (int i = len + 1; i <= len + m; i++)
			Ans[i] = str[i - len];
		len = len + m;
		Bound[cnt] = len;
		int p = 0;
		for (int i = 1; i <= m; i++) {
			int c = str[i] - 'a';
			if (!nex[p][c]) nex[p][c] = ++eid;
			p = nex[p][c];
 		}
 		if (Type[cnt] % 3 == 2 && exist[p] % 3 == 0)
 			exist[p] += 2;
 		if (Type[cnt] / 3 == 2 && exist[p] / 3 == 0)
 			exist[p] += 6; 
 		End[cnt] = p;
	}
	for (int i = 1; i <= cnt; i++) {
		if (exist[End[i + 1]] / 3 == 2 && exist[End[i]] % 3 == 0 && Type[i] % 3 != 1) {
			exist[End[i]] += 2;
		}
		if (exist[End[i - 1]] % 3 == 2 && exist[End[i]] / 3 == 0 && Type[i] / 3 != 1) {
			exist[End[i]] += 6; 
		}
	}
	for (int i = cnt; i >= 1; i--) {
		if (exist[End[i + 1]] / 3 == 2 && exist[End[i]] % 3 == 0 && Type[i] % 3 != 1) {
			exist[End[i]] += 2;
		}
		if (exist[End[i - 1]] % 3 == 2 && exist[End[i]] / 3 == 0 && Type[i] / 3 != 1) {
			exist[End[i]] += 6; 
		}
	}
	for (int i = 1; i <= cnt; i++) {
		for (int j = Bound[i - 1] + 1; j <= Bound[i]; j++)
			printf("%c", Ans[j]); 
		if ((exist[End[i]] % 3 == 2 && Type[i] % 3 != 1) || (exist[End[i + 1]] / 3 == 2 && Type[i + 1] / 3 != 1)) {
			printf(",");
		} 
		if (Type[i] % 3 == 1) printf(".");
		printf(" ");
	}
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5916kb

Test #2:

score: 0
Accepted
time: 1ms
memory: 5920kb

Test #3:

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

Test #4:

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

Test #5:

score: 0
Accepted
time: 1ms
memory: 5916kb

Test #6:

score: 0
Accepted
time: 57ms
memory: 16008kb

Test #7:

score: 0
Accepted
time: 40ms
memory: 21032kb

Test #8:

score: 0
Accepted
time: 43ms
memory: 21080kb

Test #9:

score: 0
Accepted
time: 1ms
memory: 5888kb

Test #10:

score: 0
Accepted
time: 1ms
memory: 5848kb

Test #11:

score: 0
Accepted
time: 1ms
memory: 5904kb

Test #12:

score: 0
Accepted
time: 1ms
memory: 5912kb

Test #13:

score: -100
Wrong Answer
time: 1ms
memory: 5912kb