Submission #485076

#TimeUsernameProblemLanguageResultExecution timeMemory
485076nhanbin03Watermelon (INOI20_watermelon)C++14
0 / 100
2091 ms1684 KiB
#include <bits/stdc++.h> #define task "INOI20_watermelon" #define X first #define Y second #define left ___left #define right ___right using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 0 + 10; int main() { // cin.tie(0)->sync_with_stdio(0); // cout.tie(0); if (fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".ans","w",stdout); } int n, k; cin >> n >> k; assert(k == 1); vector<int> a(n), v(n); for (int i = 0; i < n; i++) { cin >> a[i]; v[i] = i; } vector<vector<int>> lst; do { vector<int> ans(n + 1); for (int i = 0; i < n; i++) { ans[v[i]] = i; } vector<int> left(n + 2), right(n + 2); for (int i = 0; i <= n; i++) { left[i + 1] = i; right[i] = i + 1; } vector<int> cmp(n, -1); int cnt = 0; while (++cnt) { bool changed = 0; for (int i = right[0]; i <= n; i = right[i]) { // cout << i << endl; if (ans[i - 1] < ans[right[i] - 1]) { right[left[i]] = right[i]; left[right[i]] = left[i]; changed = 1; cmp[i - 1] = cnt; } } if (changed == 0) break; } bool ok = 1; for (int i = 0; i < n; i++) { if (cmp[i] != a[i]) ok = 0; } if (ok) lst.push_back(v); // cout << endl; // for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; // for (int i = 0; i < n; i++) cout << cmp[i] << " "; cout << endl; } while (next_permutation(v.begin(), v.end())); sort(lst.begin(), lst.end()); if (k > lst.size()) { cout << -1; return 0; } vector<int> ans(n); for (int i = 0; i < n; i++) { ans[lst[k - 1][i]] = i + 1; } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:69:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     if (k > lst.size()) {
      |         ~~^~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task ".ans","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...
#Verdict Execution timeMemoryGrader output
Fetching results...