SRM441 DIV2 過去問
点数 | 結果 | 備考 |
---|---|---|
250 | passed system test | 確か180ptくらい |
500 | system test failed | 後で解き直した |
1000 | Opened | 問題読んだだけ |
250 - DifferentStrings
問題文
『文字列Aの頭か尻に好きな文字をくっつけて、出来るだけ文字列Bに近づける作業をBと長さが同じになるまで続けたとき、AとBで違う文字の数を返せ』
例えばA:"asd"、B:"awersdfg"だったら
1 | 2 | 3 | 4 | ..... |
"awersdfg" | "awersdfg" | "awersdfg" | "awersdfg" | ..... |
"asd?????" | "?asd????" | "??asd???" | "???asd??" | ..... |
という風に見ていく。?には当然Bと同じ文字を入れるので無視。
public class DifferentStrings { public int minimize(String A, String B) { int diflen = B.length() - A.length(); int res = 51; for(int i=0; i<=diflen; i++){ int dif = 0; for(int j=i; j<i+A.length(); j++){ if(A.charAt(j-i)!=B.charAt(j)) dif++; } if(res>dif) res = dif; } return res; } }
500 - PaperAndPaintEasy
問題文
問題文は省略
割とさくっと書けてテストケースが通ったのでsubmit。しかしsystem testで大きい数になると通らない。
30分くらい悩んだ末にもう一度最初から書き直したがまだ大きい数が通らない。
落ち着いて考えてみたら面積計算するときにlongにキャストするのを忘れていただけでした。バカすぎる。なんでこんなのすぐ気付けないのよ!!!バカ!!!!!!
public class PaperAndPaintEasy { public long computeArea(int w, int h, int xfold, int cnt, int x1, int y1, int x2, int y2) { long res = (long)w*h; long yy = y2-y1; long xx = (xfold<x1) ? 0 : Math.min(x2,xfold) - x1; xx += (w-xfold<x1) ? 0 : Math.min(x2,w-xfold) - x1; return res - (cnt+1)*(xx*yy); } }
メモ
- 二度とあんなミスはしない…