Last active
September 8, 2015 09:35
-
-
Save jmatsu/40e9624f9e9e257a0647 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
public class Main { | |
private static final BufferedReader mReader = new BufferedReader(new InputStreamReader(System.in)); | |
public static void main(String[] args) throws Exception { | |
new Main().IamTakoyaki(); | |
} | |
private void IamTakoyaki() throws Exception { | |
int t = nextInt(); | |
int n = nextInt(); | |
int[] a = nextInts(); | |
int m = nextInt(); | |
int[] b = nextInts(); | |
int[] b_key = new int[200]; | |
Arrays.fill(b_key, 0); | |
for (int i = 0; i < b.length; i++) { | |
b_key[b[i]]++; | |
} | |
for (int i = 0; i < a.length; i++) { | |
for (int j = a[i]; j <= a[i]+t; j++) { | |
if(b_key[j] > 0){ | |
b_key[j]--; | |
m--; | |
break; | |
} | |
} | |
} | |
if (m > 0) { | |
System.out.println("no"); | |
}else{ | |
System.out.println("yes"); | |
} | |
} | |
private void IamKyaku() throws Exception { | |
int t = nextInt(); | |
int n = nextInt(); | |
int[] a = nextInts(); | |
int m = nextInt(); | |
int[] b = nextInts(); | |
int[] a_key = new int[200]; | |
Arrays.fill(a_key, 0); | |
for (int i = 0; i < a.length; i++) { | |
a_key[a[i]]++; | |
} | |
for (int i = 0; i < b.length; i++) { | |
for (int j = Math.max(0, b[i] - t); j <= b[i]; j++) { | |
if(a_key[j] > 0){ | |
a_key[j]--; | |
m--; | |
break; | |
} | |
} | |
} | |
if (m > 0) { | |
System.out.println("no"); | |
}else{ | |
System.out.println("yes"); | |
} | |
} | |
private String nextLine() throws Exception { | |
return mReader.readLine(); | |
} | |
private int nextInt() throws Exception { | |
return Integer.parseInt(nextLine()); | |
} | |
private int[] nextInts() throws Exception { | |
String[] tokens = nextTokens(); | |
int[] ints = new int[tokens.length]; | |
for (int i = 0; i < tokens.length; i++) { | |
ints[i] = Integer.parseInt(tokens[i]); | |
} | |
return ints; | |
} | |
private String[] nextTokens() throws Exception { | |
return nextLine().split(" "); | |
} | |
private String[] nextTokens(String delimita) throws Exception { | |
return nextLine().split(delimita); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Map; | |
public class Main { | |
private static final BufferedReader mReader = new BufferedReader( | |
new InputStreamReader(System.in)); | |
public static void main(String[] args) throws Exception { | |
new Main().solve(); | |
} | |
private void solve() throws Exception { | |
int n = nextInt(); | |
String[] tokens = nextTokens(); | |
System.out.println(solvePerfectly(n, tokens)); | |
} | |
private int solvePerfectly(int n, String[] tokens) throws Exception { | |
Map<String, Integer> indexMap = new HashMap<>(); | |
int left = 0; | |
int max = 0; | |
for (int i = 0; i < n; i++) { | |
if (indexMap.containsKey(tokens[i])) { | |
i = indexMap.get(tokens[i]); | |
left = i + 1; | |
indexMap.clear(); | |
} else { | |
max = Math.max(max, i - left + 1); | |
indexMap.put(tokens[i], i); | |
} | |
} | |
return max; | |
} | |
private int solveWeakPartially(int n, String[] tokens) throws Exception { | |
Map<String, Object> indexMap = new HashMap<>(); | |
final Object empty = new Object(); | |
int max = 0; | |
for (int i, length = i = 0; i < n; i++, length = 0) { | |
for (int j = i; j < n; j++, length++) { | |
if (indexMap.containsKey(tokens[j])) { | |
indexMap.clear(); | |
break; | |
} | |
indexMap.put(tokens[j], empty); | |
} | |
max = Math.max(max, length); | |
} | |
return max; | |
} | |
private int solveWeakPartially2(int n, String[] tokens) throws Exception { | |
Map<String, Object> indexMap = new HashMap<>(); | |
final Object empty = new Object(); | |
int max = 0; | |
// No way can solve this... ;D | |
for (int left = 0; left < n; left++) { | |
int right = left; | |
for (; right < n; right++) { | |
if (indexMap.containsKey(tokens[right])) { | |
indexMap.clear(); | |
break; | |
} | |
indexMap.put(tokens[right], empty); | |
} | |
max = Math.max(max, right - left); | |
} | |
return max; | |
} | |
private String nextLine() throws Exception { | |
return mReader.readLine(); | |
} | |
private int nextInt() throws Exception { | |
return Integer.parseInt(nextLine()); | |
} | |
private String[] nextTokens() throws Exception { | |
return nextLine().split(" "); | |
} | |
private String[] nextTokens(String delimita) throws Exception { | |
return nextLine().split(delimita); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
public class Main { | |
private static final BufferedReader mReader = new BufferedReader( | |
new InputStreamReader(System.in)); | |
public static void main(String[] args) throws Exception { | |
new Main().run(); | |
} | |
private void run() throws Exception { | |
String s1 = nextLine(); | |
String s2 = nextLine(); | |
String s3 = nextLine(); | |
int n = s1.length() / 2; | |
char[] s1a = s1.toCharArray(); | |
char[] s2a = s2.toCharArray(); | |
char[] s3a = s3.toCharArray(); | |
int m = 'Z' - 'A' + 1; | |
int[] s1c = new int[m]; | |
int[] s2c = new int[m]; | |
int[] s3c = new int[m]; | |
for (int i = 0; i < s1.length(); i++) { | |
s1c[s1a[i] - 'A']++; | |
s2c[s2a[i] - 'A']++; | |
s3c[s3a[i] - 'A']++; | |
} | |
int one_min, one_max = one_min = 0; | |
for (int i = 0; i < m; i++) { | |
if (s1c[i] + s2c[i] < s3c[i]) { // 不足 | |
one_max = 0; // 強制的にNOへ遷移 | |
break; | |
} | |
one_max += Math.min(s1c[i], s3c[i]); | |
one_min += Math.max(s3c[i] - s2c[i], 0); | |
} | |
if (one_min <= n && n <= one_max) { | |
System.out.println("YES"); | |
} else { | |
System.out.println("NO"); | |
} | |
} | |
private String nextLine() throws Exception { | |
return mReader.readLine(); | |
} | |
private int nextInt() throws Exception { | |
return Integer.parseInt(nextLine()); | |
} | |
private String[] nextTokens() throws Exception { | |
return nextLine().split(" "); | |
} | |
private String[] nextTokens(String delimita) throws Exception { | |
return nextLine().split(delimita); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import math | |
end=0 | |
def max(m,n): | |
if m > n: | |
return m | |
else: | |
return n | |
end | |
end | |
def min(m,n): | |
if m > n: | |
return n | |
else: | |
return m | |
end | |
end | |
s1=input() | |
s2=input() | |
s3=input() | |
N=int(len(s1)/2) | |
# 各文字の数を数える | |
alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
s1c=[s1.count(alphabet[x]) for x in range(26)] #26はアルファベットの数+1 (range(26)で0~25(含)を繰り返す | |
s2c=[s2.count(alphabet[x]) for x in range(26)] | |
s3c=[s3.count(alphabet[x]) for x in range(26)] | |
left=0 #S2が頑張る用 | |
right=0 #S1が頑張る用 | |
for i in range(26): | |
if s1c[i]+s2c[i] < s3c[i]: # どう頑張っても足りない | |
left=N*2 # 下の方の条件が絶対NOになるようにする | |
break | |
end | |
left+=max(s3c[i]-s2c[i],0) # S2が頑張るときはS2が全部出した上で,不足分をS1が出す | |
right+=min(s1c[i],s3c[i]) # S1が頑張るときはS1が全部出すか,S3が必要な分だけ | |
end | |
if left <= N <= right: # S1から使う文字数がNになるときがあるか | |
print("YES") | |
else: | |
print("NO") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment