Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active August 29, 2015 14:11
Show Gist options
  • Save cocodrips/24f8f09793a19aded922 to your computer and use it in GitHub Desktop.
Save cocodrips/24f8f09793a19aded922 to your computer and use it in GitHub Desktop.
CodeThankFestivalB
n, m = map(int, raw_input().split())
print max(n, m)
(A,B,C) = map(int, (input(), input(), input()))
print max(A * B * C, A * B + C, A + B + C, (A + B) * C)
raw_input()
all = map(int, raw_input().split())
ki = map(int, raw_input().split())
c = 0
for a, k in zip(all, ki):
if a / 2 < k:
c += 1
print c
N, T = map(int, raw_input().split())
A = []
for i in xrange(N):
A.append(int(raw_input()))
c_max = 0
for i in xrange(1, T + 1):
c = 0
for a in A:
if i % a == 0:
c += 1
c_max = max(c, c_max)
print c_max
// Pythonで塗りつぶしをすると間に合わない
// UnionFindする必要は全然ない
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
class UnionFind{
public:
int *par;
int *rank;
UnionFind(int n) {
par = new int[n]; rank = new int[n];
for (int i = 0; i < n; ++i){ par[i] = i; rank[i] = 0;}
}
~UnionFind() { delete par; delete rank; }
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x); y = find(y);
if(x == y) return;
if(rank[x] < rank[y]) par[x] = y;
else{
par[y] = x;
if(rank[x] == rank[y]) rank[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
int main(int argc, const char * argv[]){
int R, C, Rs, Cs, Rg,Cg, N;
cin >> R >> C >> Rs >> Cs >> Rg >> Cg >> N;
int table[48][48] = {0};
int r, c, h, w;
for (int i = 0; i < N; ++i){
cin >> r >> c >> h >> w;
for (int rr = r - 1; rr < r + h - 1; ++rr){
for (int cc = c - 1; cc < c + w - 1; ++cc){
table[rr][cc] = 1;
}
}
}
UnionFind unionfind(48 * 48);
int arrow[4][2] = {
1, 0,
0, 1,
};
int rr, cc;
for (int r = 0; r < R; ++r){
for (int c = 0; c < C; ++c){
for (int i = 0; i < 4; ++i){
rr = r + arrow[i][0]; cc = c + arrow[i][1];
if (0 <= rr and rr < R and 0 <= cc and cc < C){
if(table[r][c] != 1 or table[rr][cc] != 1) continue;
if(unionfind.same(r * 48 + c, rr * 48 + cc)) continue;
unionfind.unite(r * 48 + c, rr * 48 + cc);
}
}
}
}
// startとendが同じところに属してれば到達できる
if (unionfind.same((Rs - 1) * 48 + Cs - 1, (Rg - 1) * 48 + Cg - 1)){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
import sys
s = raw_input()
p1 = raw_input()
p2 = raw_input()
# dpにするとこんなん
# dp = [0] * (len(s) + 1)
# dp[0] = 1
# for i in xrange(len(s)):
# if dp[i] == 0:
# continue
# if s[i:].startswith(p1):
# dp[i + len(p1)] += dp[i]
# if s[i:].startswith(p2):
# dp[i + len(p2)] += dp[i]
#
# print dp[-1] % 1000000007
def memoize(f):
table = {}
def func(*args):
if not args in table:
table[args] = f(*args)
return table[args]
return func
@memoize
def count(s):
c = 0
if not s:
return 1
if s.endswith(p1):
c += count(s[:-len(p1)])
if s.endswith(p2):
c += count(s[:-len(p2)])
return c
sys.setrecursionlimit(1000000) #これないとmaximum recursion depth exceeded
print count(s) % 1000000007
# ゲームDPに初挑戦
# -*- coding: utf-8 -*-
N = int(raw_input())
P = int(raw_input())
# 先手が勝つことがある状態をTrueとする
# i歩目で自分のところに来ると勝つ方法がある状態をTrueとする
# dp[あとn個][p個までとれる] p >= n の時、勝てるのは自明なので、初期値は p >= n
dp = [[p >= n for p in xrange(N + 1)] for n in xrange(N + 1)]
# DP開始
for n in xrange(1, N + 1):
for p in xrange(1, n): # p個 (1 <= p < n)までとれる時
for i in xrange(1, p + 1): # pのうちから、何個を選ぶことにするか
dp[n][p] |= not dp[n - i][i + 1]
if dp[n][p]:
break
if dp[N][P]:
print "first"
else:
print "second"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment