結果
問題 | No.769 UNOシミュレータ |
ユーザー |
|
提出日時 | 2019-01-16 14:05:08 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,086 ms / 2,000 ms |
コード長 | 2,600 bytes |
コンパイル時間 | 3,106 ms |
コンパイル使用メモリ | 83,540 KB |
実行使用メモリ | 70,084 KB |
最終ジャッジ日時 | 2024-11-22 09:06:51 |
合計ジャッジ時間 | 16,417 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.*;public class Main {public static void main(String[] args) throws Exception {Scanner sc = new Scanner(System.in);int N = sc.nextInt();long M = sc.nextLong();sc.nextLine();// 酔っ払いたちの生成Yopparai yop[] = new Yopparai[N];for (int i = 0; i < N; i++) {yop[i] = new Yopparai(i + 1);}// UNOシステムboolean reverse = false;boolean skip = false;int order = 0;long drawtwoCount = 0;long drawforCount = 0;for (long i = 0; i < M; i++) {String card = sc.nextLine();if (drawtwoCount > 0 && !card.equals("drawtwo")) {yop[order].math -= drawtwoCount * 2;drawtwoCount = 0;order = nextOrder(N, reverse, order, skip);}if (drawforCount > 0 && !card.equals("drawfour")) {yop[order].math -= drawforCount * 4;drawforCount = 0;order = nextOrder(N, reverse, order, skip);}switch (card) {case "number" :break;case "drawtwo" :drawtwoCount++;break;case "drawfour" :drawforCount++;break;case "skip" :skip = true;break;case "reverse" :reverse = !reverse;break;}yop[order].math++;if (i != M - 1) order = nextOrder(N, reverse, order, skip);skip = false;}System.out.printf("%d %d", yop[order].id, yop[order].math);}// 次の酔っ払いの手番を求めるpublic static int nextOrder(int N, boolean reverse, int order, boolean skip) {int tmp = 0;if (reverse) {tmp = order - 1;tmp = tmp < 0 ? N - 1 : order - 1;if (skip) tmp = tmp - 1 < 0 ? N - 1 : tmp - 1;} else {tmp = order + 1;tmp = tmp > N - 1 ? 0 : order + 1;if (skip) tmp = tmp + 1 > N - 1 ? 0 : tmp + 1;}return tmp;}}class Yopparai {public int id;public long math;public Yopparai (int a) {id = a;math = 0;}}