Submission #1203589

#TimeUsernameProblemLanguageResultExecution timeMemory
1203589badge881JOIRIS (JOI16_joiris)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; scanf("%d%d", &n, &k); vector<int> a(n), b(k), cnt(k); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); b[i % k] = (b[i % k] + a[i]) % k; } for (int i = 1; i < n % k; ++i) { if (b[i] != b[i - 1]) { printf("-1\n"); exit(0); } } for (int i = n % k + 1; i < k; ++i) { if (b[i] != b[i - 1]) { printf("-1\n"); exit(0); } } vector<array<int, 2>> res; for (int i = 1; i < n; ++i) { while (a[i] < a[i - 1]) { a[i] += k; res.push_back({1, i}); } } for (int i = 1; i < n; ++i) { int dif = a[i] - a[i - 1]; while (dif--) { for (int j = i - k; j >= 0; j -= k) res.push_back({2, j}); for (int j = 0; j < i % k; ++j) ++cnt[j]; } } for (int i = 0; i < k - 1; ++i) { while (cnt[i] > 0) { res.push_back({1, i}); cnt[i] -= k; } } int rem = -cnt[0]; while (rem--) for (int j = n % k; j < n; j += k) res.push_back({2, j}); printf("%d\n", res.size()) for (auto [t, x] : res) printf("%d %d\n",t,x+1); return 0; }

Compilation message (stderr)

joiris.cpp: In function 'int main()':
joiris.cpp:55:12: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   55 |   printf("%d\n", res.size())
      |           ~^     ~~~~~~~~~~
      |            |             |
      |            int           std::vector<std::array<int, 2> >::size_type {aka long unsigned int}
      |           %ld
joiris.cpp:55:29: error: expected ';' before 'for'
   55 |   printf("%d\n", res.size())
      |                             ^
      |                             ;
   56 |   for (auto [t, x] : res)
      |   ~~~                        
joiris.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d%d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~
joiris.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~