QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50177#4804. Regular Expressionbvd#TL 1ms3684kbC++1.0kb2022-09-25 02:30:142022-09-25 02:30:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-25 02:30:17]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3684kb
  • [2022-09-25 02:30:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define sz(x) (int) (x).size()
string s;
vector<string> firstChar;
vector<string> secondChar;
void init() {
	rep(i,'a','z'+1) {
		string s(1, i);
		firstChar.push_back(s);
	}
	
	firstChar.push_back(".");
	secondChar = firstChar;
	secondChar.push_back("+");
	secondChar.push_back("*");
	secondChar.push_back("?");
}

void solve() {
	getline(cin, s);
	if (sz(s) == 0) {
		cout << 0 << ' ' << 1;
		return;
	}
	
	int cnt = 0;
	for (auto c: firstChar) {
		regex e = regex(c);
		if (regex_match(s, e)) cnt++;
	}
	
	if (cnt > 0) {
		cout << 1 << ' ' << cnt;
		return;
	}
	
	for (auto c: firstChar) for (auto d: secondChar) {
		regex e = regex(c+d);
		if (regex_match(s, e)) {
			cnt++;
		}
	}
	
	cout << 2 << ' ' << cnt;
	return;
}
int main() {
	ios_base::sync_with_stdio(0);
	int t; cin >> t; getline(cin, s);
	init();
	
	rep(i,0,t) {
		solve();
		cout << '\n';
	}
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
a
ab

output:

1 2
2 6

result:

ok 2 lines

Test #2:

score: -100
Time Limit Exceeded

input:

35857
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
aa
ab
ac
ad
ae
af
ag
ah
ai
aj
ak
al
am
an
ao
ap
aq
ar
as
at
au
av
aw
ax
ay
az
ba
bb
bc
bd
be
bf
bg
bh
bi
bj
bk
bl
bm
bn
bo
bp
bq
br
bs
bt
bu
bv
bw
bx
by
bz
ca
cb
cc
cd
ce
cf
cg
ch
ci
cj
ck
cl
cm
cn
co
cp
cq
cr
cs
ct
cu
cv
cw
cx
cy
cz
da
db
dc...

output:

1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 8
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 8
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
2 6
...

result: