topcoder

SRM372 div2 hard

501にボコボコにされて意気消沈してるから(読んでるひといないと思うけど) 解説はない ってうかディスプレイの文字が霞んで見えるんだよ。もうだめだよ。 conkyのuptimeが15時間超えてるよ。やばいよ。 #include <string> #include <queue> #include <vector> #include <utility> using n</utility></vector></queue></string>…

SRM385 div2 hard

数学ゲーは嫌い。 また敗北した。 ”自然数a,b,mがあって、lcm(a,b) というのが "a,bが互いに素なら1=a*x+b*yとなるx,yが存在する" というのをもとにして成立する #include <cstdio> #include <algorithm> using namespace std; typedef long long LL; class SummingArithmeticPr</algorithm></cstdio>…

SRM448 div2 hard

メモ化再起。マークでは色なので気をつけてください。 #include <cstring> #include <string> #include <vector> #define MOD 1234567891 typedef long long LL; using namespace std; class TheCardLineDivTwo { public: int n; LL cache[13][2][(1<<16)]; vector<string> cards; char m2n(ch</string></vector></string></cstring>…

SRM355 div2 hard

自作クラスでsortとかを使う場合は bool operator<(const C &c) const{ return hoge; } ってしないとコンパイルできない #include <algorithm> #include <vector> using namespace std; class LIQUID { public: int p,a; bool operator<(const LIQUID &l) const{ return p<l.p; } }; class MixingLiquids { public: double howMuch(vector <int> perce</l.p;></vector></algorithm>…

SRM430 div2 hard

久しぶりにマイ・ドストライクコースことメモ化再起するだけの問題 #include <cstring> #include <string> #include <vector> using namespace std; class ImageTraders { public: int N; vector<string> price; int cache[20][20][(1<<15)]; int rec(int from,int nowPrice,int left) { int &</string></vector></string></cstring>…

SRM373 div2 hard

殺す気か!めちゃめちゃしんどい。 線分の交差判定は検索して出てきた (x1-x2)*(y-y1)+(y1-y2)*(x1-x) これを使ったんだけど線分と長方形の辺が一致する場合のみ別に考える必要がある 参考にさせていただいたサイト: Algorithmの中の”第16回 もっと簡単に−…

SRM382 div2 hard

難しかった。 まずある数列の (偶数番目の要素の和)=(奇数番目の要素の和)である集合をP (前半の和)=(後半の和)である集合をQとするDP[i][j]をi個の要素を持ち和がjである数列の数だとする(並び替えは違うものとする) するとn(P)+n(Q)はDPで求め…

SRM386 div2 hard

挫折。

SRM497 div2 hard

めっちゃ時間がかかったけど自分で解法を見つけた。 まずinsertは必要ない。(deleteで代用できる) 次にSを前半と後半に分け(最大50通り)その2つを等しくするための最小値を 求める。 先頭同士が同じならその先頭は無視して次を考える if(s[i]==t[j]) D…

SRM500 div1 easy

まずソートして1番票をもらう人をもとめる。(ソースではNmost人としている) それから"vulnerable"な人の人数が一人になるか変わらなくなるまで シュミレーションする。 #include <algorithm> #include <vector> using namespace std; class MafiaGame { public: double probabi</vector></algorithm>…

SRM416 div2 hard

十八番のメモ化再帰。 #include <algorithm> #include <cstring> #include <string> #include <vector> using namespace std; class DancingCouples { public: vector <string> can; int bn,gn; int cache[11][11][(1<<10)]; int rec(int b,int K,int left) { int &r=cache[b][K][left]; if(r!=-1) return</string></vector></string></cstring></algorithm>…

SRM403 div2 hard

丸写し上等! ・・・・・・・解けへんかった #include <algorithm> #include <utility> #include <vector> #define INF (1<<29) using namespace std; class TheSumOfLuckyNumbers { public: int DP[1000000+1]; bool isLucky(int n) { while(0<n) if(n%10!=4 && n%10!=7) return false; else n/=10; return true; } vector <int> sum(int n) { …</n)></vector></utility></algorithm>

SRM347 div2 hard

巡回セールスマン+ビットで全探索なんだけど "~mask"を"(1 #include <sstream> #include <string> #include <vector> using namespace std; class TaxiManager { public: int dist[50][50]; int DP[12][(1<<12)]; int cost[(1<<12)]; int schedule(vector<string> roads, vector<string> _customers) </string></string></vector></string></sstream>…

SRM411 div2 hard

最大でも200*200程度の大きさでしかないので 座標を全てメモリにとってシュミレーション。 #include <vector> #include <queue> #define OFFSET 100 using namespace std; class HoleCakeCuts { public: int cake[201][201]; int cutTheCake(int cakeLength, int holeLength</queue></vector>…

SRM309 div2 hard

候補になりそうな所を全部試したら通った #include <algorithm> #include <climits> #include <sstream> #include <string> #include <vector> typedef long long LL; using namespace std; LL ABS(LL n) { return (0<=n) ? n : -n; } class SynchronizingGuideposts { public: LL minCost(vector<string> _guidepo</string></vector></string></sstream></climits></algorithm>…

SRM434 div2 hard

多倍長計算が必要、最初はdoubleでやろうとしたけど通らなかったので(解説見たので)多倍長に切り替えた。5時間ぐらいかかったんちゃうかな。 #include <string> #include <functional> #include <algorithm> #include <vector> using namespace std; int c2i(char c) { return (c<='9') ? c-'0' :</vector></algorithm></functional></string>…

SRM326 div2 hard

水面の高さを1ずつ上げていってBFSすると簡単に書けた #include <queue> #include <vector> #include <string> using namespace std; class PoolFiller { public: int BFS(vector<string> pool) { int h=pool.size(),w=pool[0].size(); int r=0; int mv[4][2]={{0,-1},{0,1},{-1,0},{1,0}};</string></string></vector></queue>…

SRM464 div2 hard

拡張幅優先探索って言うのかな。知らないけど。 prob[y][x][visited]でBFSすると通る。 ビット演算で間違えた。 #include <string> #include <queue> #include <vector> using namespace std; class Q { public: int x,y,visited; double safe; }; class ColorfulMazeTwo { public: </vector></queue></string>…

SRM330 div2 hard

久しぶりにパズル的な問題が出たので手も足も出なかった (前半分 + 前半分をひっくり返したもの)もしくは (前半分+1 + 前半分+1をひっくり返したもの)が答え #include <algorithm> #include <string> #include <vector> using namespace std; class NextPalindromicNumber { p</vector></string></algorithm>…

SRM389 div2 hard

全探索で間に合う、難しさの計算も2^6通り全て試してよい #include <string> #include <sstream> #include <vector> using namespace std; class GuitarChords { public: vector<int> strings; vector<int> chord; vector<int> play; int sN,cN,ans,all; int s2i(string s) { if(s=="A") return 0; if</int></int></int></vector></sstream></string>…

SRM384 div2 hard

また落とした。もう眠いので解説は TopCoder Statistics ここ読んでください #include <cstdio> #include <string> #include <algorithm> using namespace std; class PowerGame { public: string winner(int size0, int size1) { int DP[10005]; for(int num=0;num<10005;num++) { if(n</algorithm></string></cstdio>…

SRM329 div2 hard

日付が代わりそうなんだけど… メモ化再起で書いてしまった。通ったからいいけど何とかしないと。 汚いのであんまり参考にならないと思う。 #include <string> #include <sstream> #include <vector> #include <map> using namespace std; class ProbabilisticTranslator { public: int n; m</map></vector></sstream></string>…

SRM353 div2 hard

メモ化再起で通ると思ったらEPSでつまずいた 実数型の統合付き比較は "x #include <cstring> #include <cmath> #include <sstream> #include <string> #include <vector> #define EPS 1e-9 using namespace std; class PlatformJumper { public: int n,v,g; vector<int> x; vector<int> y; vector<int> coin; int cach</int></int></int></vector></string></sstream></cmath></cstring>…

SRM352 div2 hard

x+yP>=minimum (xはどの馬も勝たなかったときに入ってくるお金の期待値 yはどの馬かが勝ったときに出て行くお金の期待値(マイナスになる)) を変形して P=(minimum-x)y (ただしy==0かつminimum #include <vector> #define EPS 1e-16 using namespace std; class R</vector>…

SRM314 div2 hard

方針が間違ってて何度もTLEした。 cache[すでに使ったフェンス(bit)]でメモれば一発。 #include <cmath> #include <vector> #include <algorithm> using namespace std; class GrasslandFencer { public: vector<int> fences; double cache[(1<<16)]; int n; double heron(int _a,int _b,int</int></algorithm></vector></cmath>…

SRM363 div2 hard

メモ化再起で書いた。n=15に脊髄反射でbitDP的な感じ。 cache[何回目][すでにインストールされているもの(bit)]でメモ化。 #include <string> #include <sstream> #include <vector> using namespace std; class CrazyComponents { public: double cache[55][(1<<15)]; vector<int> require</int></vector></sstream></string>…

SRM366 div2 hard

最初に選ぶ所を決めたら、1回選ぶごとに右と左に分けて考えられる ターン制の問題は実装が多くなるから嫌い たぶんDPでもできる。 ていうかこのコードはちょっと頭が悪いので計算量が2倍になっている #include <cstring> #include <cstdio> #include <utility> #include <vector> using namespa</vector></utility></cstdio></cstring>…

SRM300 div2 hard

列車を動かしても本質的な(円にそって回すと)順番は変わらないので 貪欲に動かせる列車の中で一番番号の若いものから動かす ちなみにこれがdiv2hard50問め、あと50問 #include <string> using namespace std; class CircleOrder { public: string firstOrder(s</string>…

SRM439 div2 hard

swapは一番最初にすれば全部試してしまえば良いというのに気づけば一発 一回の操作ごとに前1つか、後ろ1か、前後ろ1つずつ考えなくても良くなる #include <cstring> #include <string> using namespace std; class PalindromeFactory { public: string source[50][50]; int c</string></cstring>…

SRM425 div2 hard

全探索なんだけど、しんどすぎる。 #include <algorithm> #include <string> #include <vector> #include <cmath> #include <set> using namespace std; class PiecesMover { public: int n; vector<int> pos; int DFS(set<int> se,vector<int> p) { //printf("p.size()=%d\n",p.size()); int r=(1<<28); if(p.size(</int></int></int></set></cmath></vector></string></algorithm>…