Skip to content

Instantly share code, notes, and snippets.

@akouryy
Created February 16, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akouryy/add84203f5ecc15a3cbc to your computer and use it in GitHub Desktop.
Save akouryy/add84203f5ecc15a3cbc to your computer and use it in GitHub Desktop.
頭が働いていなかったので30~31行目と32行目の違いが分からなかった
#include <bits/stdc++.h>
using namespace std;
#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++)
#define downto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i >= _##i; i--)
#define downtil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)
const int Mod = 1234567;
int main(){
int N, P;
scanf("%d %d", &N, &P);
vector<int> H(N);
times(N, k) scanf("%d", &H[k]);
vector<int> pyon(N + 1, 0);
pyon[0] = 1;
int old_k = 0, old_pyon = pyon[0], pyon_dist = 0;
times(N, k){
pyon_dist += H[k];
until(pyon_dist <= P){
old_pyon = (old_pyon - pyon[old_k] + Mod) % Mod;
pyon_dist -= H[old_k];
old_k++;
}
pyon[k + 1] = old_pyon;
old_pyon = old_pyon * 2 % Mod;
// old_pyon += pyon[k + 1] = old_pyon % Mod;
}
printf("%d\n", pyon[N] % Mod);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment