제출 #1166381

#제출 시각아이디문제언어결과실행 시간메모리
1166381nhphucJOIRIS (JOI16_joiris)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; const int N = 57; int n, k, a[N]; vector<pair<int, int>> ans; void add_ver (int i){ a[i] += k; ans.push_back({1, i}); return; } void add_hor (int i){ for (int j = i; j <= i + k - 1; ++j){ a[j] += 1; } ans.push_back({2, i}); return; } void upd (int i){ int mx = *max_element(a + i, a + i + k) + k; for (int j = 1; j < i; ++j){ while (a[j] < mx){ add_ver(j); } } for (int j = i + k; j <= n; ++j){ while (a[j] < mx){ add_ver(j); } } add_hor(i); return; } int32_t main (){ ios::sync_with_stdio(false); cin.tie(nullptr); if (fopen ("test.inp", "r")){ freopen ("test.inp", "r", stdin); freopen ("test.out", "w", stdout); } cin >> n >> k; for (int i = 1; i <= n; ++i){ cin >> a[i]; } for (int i = 1; i <= n - k + 1; ++i){ while (abs(a[i] - a[1]) % k != 0){ upd(i); } } for (int i = n - k + 1; i >= 1; --i){ while (abs(a[i + k - 1] - a[n]) % k != 0){ upd(i); } } int mx = *max_element(a + 1, a + n + 1); for (int i = 1; i <= n; ++i){ while (a[i] < mx){ add_ver(i); } if (a[i] != mx){ return cout << -1, 0; } } cout << ans.size() << "\n"; for (auto [x, y] : ans){ cout << x << " " << y << "\n"; } }

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

joiris.cpp: In function 'int32_t main()':
joiris.cpp:42:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen ("test.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joiris.cpp:43:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen ("test.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...