제출 #299685

#제출 시각아이디문제언어결과실행 시간메모리
299685E869120Cheerleaders (info1cup20_cheerleaders)C++14
25 / 100
2055 ms2172 KiB
#include <bits/stdc++.h> using namespace std; long long N; long long A[1 << 18], B[1 << 18]; long long c1[22], c2[22]; void dfs(int l, int r, int dep) { if (r - l == 1) return; int m = (l + r) / 2; for (int i = l; i < m; i++) { for (int j = m; j < r; j++) { if (A[i] < A[j]) c1[dep] += 1; if (A[i] > A[j]) c2[dep] += 1; } } dfs(l, m, dep + 1); dfs(m, r, dep + 1); } void rollback() { for (int j = 0; j < (1 << N); j++) { if (j % 2 == 0) B[j / 2] = A[j]; if (j % 2 == 1) B[(j / 2) + (1 << (N - 1))] = A[j]; } for (int j = 0; j < (1 << N); j++) A[j] = B[j]; } int main() { // Step #1. Input scanf("%d", &N); for (int i = 0; i < (1 << N); i++) scanf("%d", &A[i]); // Step #2. Saiki long long Answer = (1LL << 60); if (N == 1LL) Answer = 0; for (int i = 0; i <= N - 1; i++) { for (int j = 0; j < N; j++) { c1[j] = 0; c2[j] = 0; } dfs(0, (1 << N), 0); long long sum = 0; for (int j = 0; j < N; j++) sum += min(c1[j], c2[j]); Answer = min(Answer, sum); rollback(); } cout << Answer << endl; cout << "1" << endl; return 0; }

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

cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:32:10: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   32 |  scanf("%d", &N);
      |         ~^   ~~
      |          |   |
      |          |   long long int*
      |          int*
      |         %lld
cheerleaders.cpp:33:45: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   33 |  for (int i = 0; i < (1 << N); i++) scanf("%d", &A[i]);
      |                                            ~^   ~~~~~
      |                                             |   |
      |                                             |   long long int*
      |                                             int*
      |                                            %lld
cheerleaders.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
cheerleaders.cpp:33:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  for (int i = 0; i < (1 << N); i++) scanf("%d", &A[i]);
      |                                     ~~~~~^~~~~~~~~~~~~
#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...