↓あとで (accepted in practice)
class FoxAndMountainEasy { public: string possible(int n, int h0, int hn, string HI) { if(abs(h0-hn)>n) return "NO"; if( (n-abs(h0-hn))%2 != 0 ) return "NO"; int U=0, D=0, UD=0; if(h0<hn) U=abs(h0-hn); else D=abs(h0-hn); UD = n-abs(h0-hn); U += UD/2; D += UD/2; int u=count(ALL(HI), 'U'); int d=count(ALL(HI), 'D'); if(U<u || D<d) return "NO"; int Min=0; int pos=0; FOR(e, HI) { if(*e=='D') pos--; if(*e=='U') pos++; Min = min(Min, pos); } //if(abs(Min) > max(h0, hn)) return "NO"; // だめ if(abs(Min) > h0+U-u) return "NO"; // OK return "YES"; } };