Submission #743851

#TimeUsernameProblemLanguageResultExecution timeMemory
743851becaidoKoala Game (APIO17_koala)C++17
19 / 100
13 ms324 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,popcnt,sse4,abm") #include <bits/stdc++.h> using namespace std; #ifndef WAIMAI #include "koala.h" #endif // WAIMAI #ifdef WAIMAI #define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE) void dout() {cout << '\n';} template<typename T, typename...U> void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);} #else #define debug(...) 7122 #endif #define ll long long #define Waimai ios::sync_with_stdio(false), cin.tie(0) #define FOR(x,a,b) for (int x = a, I = b; x <= I; x++) #define pb emplace_back #define F first #define S second #ifdef WAIMAI void playRound(int *B, int *R); #endif // WAIMAI const int SIZE = 105; int a[SIZE], b[SIZE]; int minValue(int N, int W) { a[0] = 1; fill(a + 1, a + N, 0); playRound(a, b); FOR (i, 0, N - 1) if (b[i] == 0) return i; } int maxValue(int N, int W) { vector<int> big(N); iota(big.begin(), big.end(), 0); while (big.size() > 1) { int w = W / big.size(); fill(a, a + N, 0); for (int p : big) a[p] = w; playRound(a, b); vector<int> tmp; for (int p : big) if (b[p] > a[p]) tmp.pb(p); big = tmp; } if (big.size() == 0) return -1; return big[0]; } int greaterValue(int N, int W) { // TODO: Implement Subtask 3 solution here. // You may leave this function unmodified if you are not attempting this // subtask. return 0; } void allValues(int N, int W, int *P) { if (W == 2*N) { // TODO: Implement Subtask 4 solution here. // You may leave this block unmodified if you are not attempting this // subtask. } else { // TODO: Implement Subtask 5 solution here. // You may leave this block unmodified if you are not attempting this // subtask. } } /* in1 1 1 6 6 5 3 2 1 6 4 out1 3 in2 2 1 6 6 5 3 2 1 6 4 in3 3 1 6 6 5 3 2 1 6 4 in4 4 1 6 12 5 3 2 1 6 4 in5 4 1 6 6 5 3 2 1 6 4 */ #ifdef WAIMAI static int N, W; static int P[105]; static int maxQueries = 3200; static int numQueries; static void runGame(int F); static void grader(); int main() { grader(); return 0; } void playRound(int *B, int *R) { int i, j; int S = 0; for (i=0;i<N;++i) { if ( !(B[i] >= 0 && B[i] <= W) ) { printf("Invalid query.\n"); exit(0); } S += B[i]; } if (S > W) { printf("Invalid query.\n"); exit(0); } numQueries++; if (numQueries > maxQueries) { printf("Too many queries.\n"); exit(0); } int cache[2][205]; int num[2][205]; char taken[105][205]; for (i=0;i<205;++i) { cache[1][i] = 0; num[1][i] = 0; } for (i=0;i<N;++i) { int v = B[i]+1; int ii = i&1; int o = ii^1; for (j=0;j<=W;++j) { cache[ii][j] = cache[o][j]; num[ii][j] = num[o][j]; taken[i][j] = 0; } for (j=W;j>=v;--j) { int h = cache[o][j-v] + P[i]; int hn = num[o][j-v] + 1; if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) { cache[ii][j] = h; num[ii][j] = hn; taken[i][j] = 1; } else { taken[i][j] = 0; } } } int cur = W; for (i=N-1;i>=0;--i) { R[i] = taken[i][cur] ? (B[i] + 1) : 0; cur -= R[i]; } } static void runGame(int F) { int i; scanf("%d %d",&N,&W); printf("random?\n"); int x; scanf("%d", &x); if (x == 1) { printf("random array = "); mt19937 rng(0); iota(P, P + N, 1); shuffle(P, P + N, rng); for (int i = 0; i < N; i++) printf("%d ", P[i]); printf("\n"); } else { for (i=0;i<N;++i) { scanf("%d",&P[i]); } } numQueries = 0; if (F == 1) { printf("%d\n", minValue(N, W)); } else if (F == 2) { printf("%d\n", maxValue(N, W)); } else if (F == 3) { printf("%d\n", greaterValue(N, W)); } else if (F == 4) { int userP[105]; allValues(N, W, userP); for (i=0;i<N;i++) { printf("%d ",userP[i]); } printf("\n"); } printf("Made %d calls to playRound.\n", numQueries); } static void grader() { int i; int F, G; scanf("%d %d",&F,&G); for (i=0;i<G;i++) { runGame(F); } } #endif // WAIMAI

Compilation message (stderr)

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:39:1: warning: control reaches end of non-void function [-Wreturn-type]
   39 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...