Submission #403105

#TimeUsernameProblemLanguageResultExecution timeMemory
403105rainboyParrots (IOI11_parrots)C11
100 / 100
671 ms21900 KiB
#include "encoder.h" #include "encoderlib.h" #include <string.h> #define N 64 #define M (N / 4) #define A 256 #define B 4294967296 #define K (N * 5) long long dp[A + 1][K + 1][M]; void add(long long *aa, long long *bb, long long *cc) { int i; for (i = 0; i < M; i++) cc[i] = aa[i] + bb[i]; for (i = 0; i < M; i++) if (cc[i] >= B) { if (i + 1 == M) cc[i] = B; else cc[i] -= B, cc[i + 1]++; } } void sub(long long *aa, long long *bb) { int i; for (i = 0; i < M; i++) aa[i] -= bb[i]; for (i = 0; i < M; i++) if (aa[i] < 0) aa[i] += B, aa[i + 1]--; } void init() { int a, k; for (a = 0; a <= A; a++) for (k = 0; k <= K; k++) if (a == 0 || k == 0) memset(dp[a][k], 0, M * sizeof *dp[a][k]), dp[a][k][0] = 1; else add(dp[a - 1][k], dp[a][k - 1], dp[a][k]); } int lt(long long *aa, long long *bb) { int i; for (i = M - 1; i >= 0; i--) if (aa[i] != bb[i]) return aa[i] < bb[i]; return 0; } void encode(int n, int *aa_) { static long long aa[M]; int i, a, k; init(); memset(aa, 0, M * sizeof *aa); for (i = 0; i < n; i++) aa[i / 4] |= (long long) aa_[i] << i % 4 * 8; a = A, k = K; while (a > 0 || k > 0) if (k > 0 && lt(aa, dp[a][k - 1])) { if (a < A) send(a); k--; } else { if (k > 0) sub(aa, dp[a][k - 1]); a--; } }
#include "decoder.h" #include "decoderlib.h" #include <string.h> #define N 64 #define M (N / 4) #define A 256 #define B 4294967296 #define K (N * 5) long long dp_[A + 1][K + 1][M]; void add_(long long *aa, long long *bb, long long *cc) { int i; for (i = 0; i < M; i++) cc[i] = aa[i] + bb[i]; for (i = 0; i < M; i++) if (cc[i] >= B) { if (i + 1 == M) cc[i] = B; else cc[i] -= B, cc[i + 1]++; } } void init_() { int a, k; for (a = 0; a <= A; a++) for (k = 0; k <= K; k++) if (a == 0 || k == 0) memset(dp_[a][k], 0, M * sizeof *dp_[a][k]), dp_[a][k][0] = 1; else add_(dp_[a - 1][k], dp_[a][k - 1], dp_[a][k]); } void decode(int n, int l, int *bb) { static long long aa[M]; static int kk[A]; int i, a, k; init_(); memset(kk, 0, A * sizeof *kk); for (i = 0; i < l; i++) kk[bb[i]]++; memset(aa, 0, M * sizeof *aa); k = 0; for (a = 0; a < A; a++) { k += kk[a]; if (k > 0) add_(aa, dp_[a + 1][k - 1], aa); } for (i = 0; i < n; i++) output(aa[i / 4] >> i % 4 * 8 & A - 1); }

Compilation message (stderr)

grader_decoder.c: In function 'main':
grader_decoder.c:86:2: warning: implicit declaration of function 'fcloseall'; did you mean 'fclose'? [-Wimplicit-function-declaration]
   86 |  fcloseall();
      |  ^~~~~~~~~
      |  fclose
decoder.c: In function 'decode':
decoder.c:55:33: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   55 |   output(aa[i / 4] >> i % 4 * 8 & A - 1);
      |                                 ^
#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...