Download 2019/round2/grading.cpp from hackercupai/hackercup: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/datasets/hackercupai/hackercup/resolve/main/2019/round2/grading.cpp
- Command line
-
hf download hf://datasets/hackercupai/hackercup/2019/round2/grading.cpp
-
curl -L -o grading.cpp https://huggingface.co/datasets/hackercupai/hackercup/resolve/main/2019/round2/grading.cpp
3.08 kB
| // Grading | |
| // Solution by Jacob Plachta | |
| using namespace std; | |
| template<typename T> T Abs(T x) { return(x<0 ? -x : x); } | |
| template<typename T> T Sqr(T x) { return(x*x); } | |
| string plural(string s) { return(Sz(s) && s[Sz(s)-1]=='x' ? s+"en" : s+"s"); } | |
| const int INF = (int)1e9; | |
| const LD EPS = 1e-12; | |
| const LD PI = acos(-1.0); | |
| bool Read(int &x) | |
| { | |
| char c,r=0,n=0; | |
| x=0; | |
| for(;;) | |
| { | |
| c=GETCHAR(); | |
| if ((c<0) && (!r)) | |
| return(0); | |
| if ((c=='-') && (!r)) | |
| n=1; | |
| else | |
| if ((c>='0') && (c<='9')) | |
| x=x*10+c-'0',r=1; | |
| else | |
| if (r) | |
| break; | |
| } | |
| if (n) | |
| x=-x; | |
| return(1); | |
| } | |
| int H,S,K; | |
| char P[LIM][LIM]; | |
| // dyn[i][s][p] = min discards for at most s context switches in the first i papers in stack, | |
| // with current paper type being p | |
| int dyn[LIM][LIM][2]; | |
| // minD[f][s] = min total discards for at most s context switches assuming first paper type is f | |
| int minD[2][LIM]; | |
| // ans[d] = min total context switches for at most d discards | |
| int ans[LIM2]; | |
| int main() | |
| { | |
| if (DEBUG) | |
| freopen("in.txt","r",stdin); | |
| // vars | |
| int T,t; | |
| int i,j,f,s,p,d; | |
| // testcase loop | |
| Read(T); | |
| Fox1(t,T) | |
| { | |
| // input | |
| Read(H),Read(S),Read(K); | |
| Fox(i,H) | |
| scanf("%s",&P[i]); | |
| // DP on each stack | |
| Fill(minD,0); | |
| Fox(f,2) | |
| Fox(j,S) | |
| { | |
| Fill(dyn,60); | |
| Fox(s,H+1) | |
| dyn[0][s][f]=0; | |
| Fox(i,H) | |
| Fox(s,H+1) | |
| Fox(p,2) | |
| { | |
| d=dyn[i][s][p]; | |
| int p2=P[i][j]-'A'; | |
| Min(dyn[i+1][s+(p2==p ? 0 : 1)][p2],d); // grade | |
| Min(dyn[i+1][s][p],d+1); // discard | |
| } | |
| Fox(s,H+1) | |
| minD[f][s]+=min(dyn[H][s][0],dyn[H][s][1]); | |
| } | |
| // compute answers | |
| Fill(ans,60); | |
| Fox(f,2) | |
| Fox(s,H+1) | |
| Min(ans[minD[f][s]],s); | |
| Fox(d,H*S) | |
| Min(ans[d+1],ans[d]); | |
| // process queries | |
| printf("Case #%d:",t); | |
| while (K--) | |
| { | |
| Read(d); | |
| printf(" %d",ans[d]+1); | |
| } | |
| printf("\n"); | |
| } | |
| return(0); | |
| } |