SRM 538 250pt : EvenRoute
問題概要
あなたは原点にいて4近傍のどれかに移動できる。いくつか点があって全ての点を1度以上尋ねて最後はどれかの点で終わるようなパスを考える。そのパスの経路長が指定された偶奇にできるかどうか判定する問題。
解法
最後の点をどれにするかでパリティは調節できる。
acceptされたコード
本番中は何を考えていたのかコメントしたようなコードを送っていた。ホント頭がどうかしていた。
#include <vector> #include <string> #include <numeric> using namespace std; struct EvenRoute { string isItPossible(vector <int> x, vector <int> y, int wantedParity) { for(int i=0; i<(int)x.size(); i++){ if( ((x[i] + y[i])&1) == wantedParity ){ return "CAN"; } } return "CANNOT"; //return ((accumulate(x.begin(), x.end(), 0) + accumulate(y.begin(), y.end(), 0))&1) == wantedParity ? "CAN" : "CANNOT"; } };