Submission #722794

#TimeUsernameProblemLanguageResultExecution timeMemory
722794rainboyBad Codes (CCO19_day2problem3)C11
4 / 100
1 ms596 KiB
#include <stdio.h> #include <string.h> #define N 50 #define L 50 #define N_ (N * L + 2) #define INF 0x3f3f3f3f int min(int a, int b) { return a < b ? a : b; } int main() { static char cc[L + 1]; static int ll[N], tt[N_][2], ii[N_], dd[N_ * N_], qu[2][N_ * N_], hh[2], cnt[2]; int n, n_, h, i, s, s_, t, t_, st, d, d_; scanf("%d%*d", &n); memset(ii, -1, N_ * sizeof *ii); n_ = 2, d_ = INF; for (i = 0; i < n; i++) { scanf("%s", cc), ll[i] = strlen(cc); for (h = 0, s = 1; h < ll[i]; h++) { d = cc[h] - '0'; if (!tt[s][d]) tt[s][d] = n_++; s = tt[s][d]; } if (ii[s] == -1) ii[s] = i; else d_ = min(d_, ll[i]); } memset(dd, 0x3f, n_ * n_ * sizeof *dd); for (s = 1; s < n_; s++) if (ii[s] != -1) dd[s * n_ + 1] = ll[ii[s]], qu[0][cnt[0]++] = s * n_ + 1; while (hh[0] < cnt[0] || hh[1] < cnt[1]) { st = hh[1] == cnt[1] || hh[0] < cnt[0] && dd[qu[0][hh[0]]] < dd[qu[1][hh[1]]] ? qu[0][hh[0]++] : qu[1][hh[1]++], s = st / n_, t = st % n_, d = dd[st] + 1; if (dd[st] >= d_) { printf("%d\n", d_); return 0; } if (s == 1 && t == 1) { printf("%d\n", dd[st]); return 0; } if ((s_ = tt[s][0]) && (t_ = tt[t][0])) { if (dd[s_ * n_ + t_] > d) dd[s_ * n_ + t_] = d, qu[1][cnt[1]++] = s_ * n_ + t_; if (ii[t_] != -1 && dd[s_ * n_ + 1] > d) dd[s_ * n_ + 1] = d, qu[1][cnt[1]++] = s_ * n_ + 1; if (ii[s_] != -1 && dd[1 * n_ + t_] > d) dd[1 * n_ + t_] = d, qu[1][cnt[1]++] = 1 * n_ + t_; if (ii[s_] != -1 && ii[t_] != -1 && dd[1 * n_ + 1] > d) dd[1 * n_ + 1] = d, qu[1][cnt[1]++] = 1 * n_ + 1; } if ((s_ = tt[s][1]) && (t_ = tt[t][1])) { if (dd[s_ * n_ + t_] > d) dd[s_ * n_ + t_] = d, qu[1][cnt[1]++] = s_ * n_ + t_; if (ii[t_] != -1 && dd[s_ * n_ + 1] > d) dd[s_ * n_ + 1] = d, qu[1][cnt[1]++] = s_ * n_ + 1; if (ii[s_] != -1 && dd[1 * n_ + t_] > d) dd[1 * n_ + t_] = d, qu[1][cnt[1]++] = 1 * n_ + t_; if (ii[s_] != -1 && ii[t_] != -1 && dd[1 * n_ + 1] > d) dd[1 * n_ + 1] = d, qu[1][cnt[1]++] = 1 * n_ + 1; } } printf("-1\n"); return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:37:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   37 |   st = hh[1] == cnt[1] || hh[0] < cnt[0] && dd[qu[0][hh[0]]] < dd[qu[1][hh[1]]] ? qu[0][hh[0]++] : qu[1][hh[1]++], s = st / n_, t = st % n_, d = dd[st] + 1;
      |                           ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%d%*d", &n);
      |  ^~~~~~~~~~~~~~~~~~
Main.c:20:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%s", cc), ll[i] = strlen(cc);
      |   ^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...