CodeChef submission 64039 (C++ 4.0.0-8) plaintext list. Status: AC, problem F2, contest AUG09. By gmark (Mark Greve), 2009-08-04 12:49:02.
// Bytelandian Robots // Source: CodeChef August 2009 Algorithm Challenge // CodeChef ID: F2 // Date: 02-08-2009 // Author: Mark Greve #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; const int MOD = 7051954; char s[100000]; int N,L,A,B; const int MAX=1001; int nm[MAX], np[MAX]; int dp[MAX][2*MAX+5][3]; const int PLUS=0, MINUS=1,NONE=2; int go(int,int); int go2(int,int,int); bool ok(int d) { return !(A+d>L || A+d<0); } int go2(int at, int d, int next) { if (A+d<B && A+d+(N-at)<B) return 0; // pruning if (A+d>B && A+d-(N-at)>B) return 0; // pruning if (next==NONE) return d==B-A; int& ref = dp[at][d+N][next]; if (ref!=-1) return ref; ref = 0; if (next==PLUS && np[at]!=-1) ref=go(np[at]+1, d+1); if (next==MINUS && nm[at]!=-1) ref=go(nm[at]+1, d-1); return ref; } int go(int at, int d) { if (!ok(d)) return 0; int res = 0; res = res + go2(at,d,PLUS); if (res>=MOD) res -= MOD; res = res + go2(at,d,MINUS); if (res>=MOD) res -= MOD; res = res + go2(at,d,NONE); if (res>=MOD) res -= MOD; return res; } int main() { int NCASES; while (NCASES-- > 0) { int curp = -1, curm = -1; np[N]=nm[N]=-1; for (int i=N-1;i>=0;--i) { if (s[i]=='+') curp = i; if (s[i]=='-') curm = i; nm[i] = curm; np[i] = curp; } for (int i=0;i<N;++i) for (int j=0;j<=2*N;++j) dp[i][j][0] = dp[i][j][1] = dp[i][j][2] = -1; } }
Comments

