제출 #949839

#제출 시각아이디문제언어결과실행 시간메모리
949839rainboy전화번호 나누기 (KPI13_telephone)C11
1 / 1
928 ms468 KiB
#include <stdio.h> #include <string.h> #define N 512 #define K 30 #define B 1000000000000000000 #define INF 0x3f3f3f3f3f3f3f3fLL void concat(long long *aa, int d) { int h, d_; for (h = 0; h < K; h++) { d_ = aa[h] / (B / 10); aa[h] = aa[h] % (B / 10) * 10 + d; d = d_; } } void add(long long *aa, long long *bb, long long *cc) { int h; for (h = 0; h < K; h++) cc[h] = aa[h] + bb[h]; for (h = 0; h + 1 < K; h++) if (cc[h] >= B) cc[h] -= B, cc[h + 1]++; } void chmin(long long *aa, long long *bb) { int h; for (h = K - 1; h >= 0; h--) if (aa[h] != bb[h]) { if (aa[h] > bb[h]) memcpy(aa, bb, K * sizeof *bb); return; } } void print(long long *aa) { int h; h = K - 1; while (h > 0 && aa[h] == 0) h--; printf("%lld", aa[h]); while (h--) printf("%018lld", aa[h]); printf("\n"); } int main() { static char cc[N + 1]; static long long dp[N + 1][K], aa[K], bb[K]; int n, k, i, j; scanf("%s%d", cc, &k), n = strlen(cc); for (i = 1; i <= n; i++) memset(dp[i], 0x3f, K * sizeof *dp[i]); while (k--) for (i = n - 1; i >= 0; i--) { if (dp[i][0] == INF) continue; memset(aa, 0, K * sizeof *aa); for (j = i; j < n; j++) { concat(aa, cc[j] - '0'); add(dp[i], aa, bb); chmin(dp[j + 1], bb); } } print(dp[n]); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

telephone.c: In function 'main':
telephone.c:57:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |  scanf("%s%d", cc, &k), n = strlen(cc);
      |  ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...