2010-12-05から1日間の記事一覧

Codeforces Beta Round #43 F. Hercule Poirot Problem

Hercule Poirot Problem動的計画法。i番目の列のj番目まで石を置いたときに得られる最大コイン数を覚えてく。O(nm)じゃないとTLE。cinを使うとTLE。 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, m; scanf("%d%d",&n,&m); vector<long long></long></algorithm></vector></iostream>…

Codeforces Beta Round #43 D. Parking Lot

Parking LotLに対してnが小さいので、駐車場の状態ではなく止まっている車を記憶しておく。あらかじめ1台車を停めておくと楽。 L,b,f = map(int,raw_input().split()) n = input() P = [(-b,0,-1)] # position,length,id for i in range(n): t,l = map(int,…

Codeforces Beta Round #43 C. Hamsters and Tigers

Hamsters and Tigers条件を満たす動物の並びはn通りしかないので、n通りの並びについて交換の回数を数える。 n = input() A = raw_input() B = "".join(sorted(A)) ans = n for i in range(n): c = 0 for j in range(n): if A[j]!=B[j]: c += 1 ans = min(an…

Codeforces Beta Round #43 B. T-shirts from Sponsor

T-shirts from Sponsor size = ["S","M","L","XL","XXL"] N = map(int,raw_input().split()) K = input() for i in range(K): c = raw_input() for d in [0,+1,-1,+2,-2,+3,-3,+4,-4]: t = size.index(c)+d if 0<=t<5 and N[t]>0: print size[t] N[t] -= 1 b…

Codeforces Beta Round #43 A. Ball Game

Ball Game c = 0 n = input() for i in range(n-1): c = (c+i+1)%n print c+1, print

Codeforces Beta Round #43

A + 00:11 B + 00:26 C + 00:34 D + 01:36 E +2 02:02 結果 81位 1745 → 1849 良い感じ。EはTLE。入力のサイズが大きい場合にcinは禁物....〆(・ω・` )