QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97595#5607. Cribbage On SteroidsNicolas125841WA 72ms54336kbJava111.5kb2023-04-17 11:52:272023-04-17 11:52:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-17 11:52:30]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:54336kb
  • [2023-04-17 11:52:27]
  • 提交

answer

import java.io.*;
import java.util.*;

public class crib {
	static int n;

	public static void main(String args[]) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		
		n = Integer.parseInt(br.readLine());
		int[] tb = new int[13];
		
		while(n > 0) {
			Arrays.asList(br.readLine().split(" "))
				.forEach(str -> {
					tb[ctoi(str.charAt(0))]++;
					n--;
				});
		}
		
		int score = 0;
		
		int[] dp = new int[16];
		
		dp[0] = 1;
		
		for(int i = 0; i < 13; i++) {
			for(int j = 0; j < tb[i]; j++) {
				for(int k = 15; k >= 0; k--)
					if(k + ps(i) <= 15)
						dp[k + ps(i)] += dp[k];
			}
		}
		
		score += 2 * dp[15];
		
		for(int i = 0; i < 13; i++)
			score += tb[i] * (tb[i]-1);
		
		int rl = 0;
		int ways = 1;
		
		for(int i = 0; i < 13; i++) {
			if(tb[i] == 0) {
				if(rl >= 3)
					score += rl * ways;
				
				rl = 0;
				ways = 1;
			}else {
				rl++;
				ways *= tb[i];
			}
		}
		
		if(rl >= 3)
			score += rl * ways;
		
		pw.println(score);
		pw.close();
	}
	
	static int ps(int r) {
		if(r == 0)
			return 1;
		else if(r < 9)
			return r+1;
		else
			return 10;
	}
	
	static int ctoi(char c) {
		if(c == 'A')
			return 0;
		else if(Character.isDigit(c))
			return c-'0'-1;
		else if(c == 'T')
			return 9;
		else if(c == 'J')
			return 10;
		else if(c == 'Q')
			return 11;
		else
			return 12;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 63ms
memory: 54336kb

input:

5
4 5 6 5 5

output:

23

result:

ok single line: '23'

Test #2:

score: 0
Accepted
time: 66ms
memory: 52256kb

input:

13
A 2 3 4 5
6 7 8 9 T
J Q K

output:

71

result:

ok single line: '71'

Test #3:

score: 0
Accepted
time: 53ms
memory: 52276kb

input:

10
2 2 3 4 5 8 9 T J Q

output:

45

result:

ok single line: '45'

Test #4:

score: 0
Accepted
time: 62ms
memory: 51952kb

input:

5
5 5 5 5 J

output:

28

result:

ok single line: '28'

Test #5:

score: 0
Accepted
time: 67ms
memory: 54204kb

input:

5
5 5 5 5 5

output:

40

result:

ok single line: '40'

Test #6:

score: 0
Accepted
time: 66ms
memory: 52480kb

input:

11
A 2 3 5 6 7 8 T J Q K

output:

41

result:

ok single line: '41'

Test #7:

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

input:

20
A 2 3 4 5
A 2 3 4 5
A 2 3 4 5
A 2 3 4 5

output:

20308

result:

ok single line: '20308'

Test #8:

score: 0
Accepted
time: 72ms
memory: 51968kb

input:

7
9 6 5 A 4 7 8

output:

16

result:

ok single line: '16'

Test #9:

score: 0
Accepted
time: 55ms
memory: 51980kb

input:

11
Q K
2 2 2
3 3 3
A A
4

output:

224

result:

ok single line: '224'

Test #10:

score: -100
Wrong Answer
time: 46ms
memory: 52244kb

input:

100
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A
A A A A A A A A A A A A A A A A A A A A

output:

-1316781844

result:

wrong answer 1st lines differ - expected: '506676942699987180', found: '-1316781844'