제출 #428631

#제출 시각아이디문제언어결과실행 시간메모리
428631shenxyCheerleaders (info1cup20_cheerleaders)C++11
41 / 100
846 ms140244 KiB
#include <cstdio> #include <algorithm> #include <vector> using namespace std; int inv[17], niv[17]; struct seg { int s, v; seg *l, *r; seg(int _s) { s = _s, v = 0; if (s) { l = new seg(s - 1); r = new seg(s - 1); } } void update(int i) { if (s) { if (i < (1 << (s - 1))) l -> update(i), inv[s - 1] += r -> v; else r -> update(i - (1 << (s - 1))), niv[s - 1] += l -> v; v = l -> v + r -> v; } else ++v; } } *root; int main() { int N, h; scanf("%d", &N); if (N == 0) { printf("0\n11"); return 0; } int a[1 << N], ans[N]; vector<int> res[N]; fill_n(ans, N, 0); for (int i = 0; i < (1 << N); ++i) scanf("%d", &h), a[h] = i; for (int i = 0; i < N; ++i) { for (int j = 0; j < i; ++j) res[i].push_back(2); root = new seg(N); fill_n(inv, N, 0); fill_n(niv, N, 0); for (int j = 0; j < (1 << N); ++j) root -> update(a[j]); for (int j = N - 1; j >= 0; --j) { if (inv[j] > niv[j]) res[i].push_back(1), ans[i] += niv[j]; else ans[i] += inv[j]; res[i].push_back(2); } for (int j = 0; j < (1 << N); ++j) a[j] = (a[j] >> 1) + ((1 & a[j]) << (N - 1)); } printf("%d\n", *min_element(ans, ans + N)); for (int i: res[min_element(ans, ans + N) - ans]) printf("%d", i); return 0; }

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

cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
cheerleaders.cpp:34:42: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  for (int i = 0; i < (1 << N); ++i) scanf("%d", &h), a[h] = 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...