Skip to content

Commit 3c35c03

Browse files
authored
Merge pull request #55 from tossy310/ryoissy
fix statement tsunahiki and add solutions
2 parents 5e0322a + 44d2b15 commit 3c35c03

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed

tsunahiki/java-tossy/SOLUTION

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8; mode: python -*-
2+
3+
## Solution
4+
#c_solution(src='main.c') # -lm -O2 as default
5+
#cxx_solution(src='main.cc', flags=[]) # -std=c++11 -O2 as default
6+
java_solution(src='Tsunahiki.java', encoding='UTF-8', mainclass='Tsunahiki')
7+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main',
8+
# challenge_cases=[])
9+
#java_solution(src='Main.java', encoding='UTF-8', mainclass='Main',
10+
# challenge_cases=['10_corner*.in'])
11+
#script_solution(src='main.sh') # shebang line is required
12+
#script_solution(src='main.pl') # shebang line is required
13+
#script_solution(src='main.py') # shebang line is required
14+
#script_solution(src='main.rb') # shebang line is required
15+
#js_solution(src='main.js') # javascript (nodejs)
16+
#hs_solution(src='main.hs') # haskell (stack + ghc)
17+
#cs_solution(src='main.cs') # C# (mono)
18+
19+
## Score
20+
#expected_score(100)

tsunahiki/java-tossy/Tsunahiki.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import java.util.Scanner;
2+
3+
// O(N^2) solution
4+
public class Tsunahiki {
5+
private static final Scanner sc = new Scanner(System.in);
6+
private static final int MAX_N = 100;
7+
static final int a[] = new int[MAX_N];
8+
static final int b[] = new int[MAX_N];
9+
10+
private static boolean check(final int n, final int ans) {
11+
// try to win `ans` times
12+
// we only need to check following inequality
13+
// b[0] < a[n-ans]
14+
// b[1] < a[n-ans+1]
15+
// ...
16+
// b[ans-1] < a[n-1]
17+
18+
for (int i = 0; i < ans; i++) {
19+
if (b[i] >= a[n - ans + i]) return false;
20+
}
21+
22+
return true;
23+
}
24+
25+
private static void solve() {
26+
final int n = sc.nextInt();
27+
for (int i = 0; i < n; i++) {
28+
a[i] = sc.nextInt();
29+
}
30+
for (int i = 0; i < n; i++) {
31+
b[i] = sc.nextInt();
32+
}
33+
34+
for (int ans = n; ans >= 0; ans--) {
35+
if (check(n, ans)) {
36+
System.out.println(ans);
37+
return;
38+
}
39+
}
40+
41+
throw new RuntimeException();
42+
}
43+
44+
public static void main(final String[] args) {
45+
final int T = sc.nextInt();
46+
for (int i = 0; i < T; i++) {
47+
solve();
48+
}
49+
}
50+
}

tsunahiki/statement.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Description
22
20XX年、情報理工学部のオリエンでは2つの軍に分かれての綱引き対決が恒例行事となり、今年は計$2N$人の新入生がカトー軍とサトー軍に$N$人ずつ分かれて対決する事になりました。
33

4-
綱引きは1vs1の対戦を計$N$回行います。$i$回目の対戦では各軍の$i$人目の生徒同士が戦い、強い方の生徒が勝利します。ただし、強さが同じ場合はカトー軍の生徒が勝利します
5-
各生徒の綱引きの強さはサトー軍が数列$A$, カトー軍が数列$B$にそれぞれ数値化されています。サトー軍の$i$人目の生徒の強さは$A_i$, カトー軍の$i$人目の生徒の強さは$B_i$です。
4+
綱引きは1vs1の対戦を計$N$回行います。$i$回目の対戦では各軍の$i$人目の生徒同士が戦い、強い方の生徒が勝利します。ただし、強さが同じ場合はサトー軍の生徒が勝利します
5+
各生徒の綱引きの強さはカトー軍が数列$A$, サトー軍が数列$B$にそれぞれ数値化されています。カトー軍の$i$人目の生徒の強さは$A_i$, サトー軍の$i$人目の生徒の強さは$B_i$です。
66

7-
今年のサトー軍の大将であるあなたは、自軍の生徒の登場順を並び替える事で自軍の勝利数を最大化したいと考えています。
8-
すなわち、相手の強い生徒に捨て駒として弱い生徒をぶつけたり、自分の強い生徒を相手の弱い生徒にぶつけて勝数を稼ぐ事ができます
7+
今年のカトー軍の大将であるあなたは、自軍の生徒の登場順を並び替える事で自軍の勝利数を最大化したいと考えています。
8+
勝利数を最大化するために、自軍の弱い生徒を捨て駒として強い生徒にぶつける戦略や、自分の強い生徒を相手の弱い生徒と戦わせて確実に勝数を稼ぐ戦略等、様々な戦略が考えられます
99

10-
カトー軍は弱い生徒から順に綱引き対決に登場してきます。適切にサトー軍の生徒を並び替える事で、サトー軍が勝利できる綱引き勝負の回数を最大化してください
10+
サトー軍は弱い生徒から順に綱引き対決に登場してきます。適切にカトー軍の生徒を並び替え、カトー軍の勝利回数の最大値を求めてください
1111

1212
# Constraints
1313
各軍の生徒の強さを表す数列$A$, $B$は昇順にソートされて与えられている。
@@ -23,12 +23,12 @@ $1 \leq N, A_i , B_i \leq 100$
2323

2424
```
2525
$N$
26-
$A_1$, $A_2$, ..., $A_N$
27-
$B_1$, $B_2$, ..., $B_N$
26+
$A_1$ $A_2$ ... $A_N$
27+
$B_1$ $B_2$ ... $B_N$
2828
```
2929

3030
# Output
31-
各テストケースに対して、サトー軍が勝利できる試合数の最大値を1行ずつ出力せよ
31+
各テストケースに対して、カトー軍が勝利できる試合数の最大値を1行ずつ出力せよ
3232

3333

3434
# Sample Input
@@ -51,3 +51,8 @@ $B_1$, $B_2$, ..., $B_N$
5151
0
5252
4
5353
```
54+
最初のケースは順番に生徒を戦わせることで2回カトー軍が勝つことができます。
55+
56+
2番目のケースではカトー軍のどの生徒もサトー軍のどの生徒より弱いため、カトー軍は一度も勝つことができません。
57+
58+
3番目のケースでは、カトー軍の4人目の生徒と5人目の生徒を入れ替える事で、4回カトー軍が勝つことができます。

0 commit comments

Comments
 (0)