# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1114896 | 2024-11-19T18:00:59 Z | ortsac | Dancing Elephants (IOI11_elephants) | C++17 | 0 ms | 0 KB |
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define fr first #define se second int32_t main() { int n, s; cin >> n >> s; vector<pii> v(n); for (int i = 0; i < n; i++) { cin >> v[i].fr; v[i].fr++; v[i].fr %= s; v[i].se = (i + 1); } sort(v.begin(), v.end()); vector<pii> ord; int mi = 1e9; do { int qtd = 0; int pf = 0; for (int i = 0; i < (n - 1); i++) { pf = ((pf + v[i].fr) % s); if (pf == (s - 1)) { qtd++; pf = 0; } } if (qtd < mi) { mi = qtd; ord = v; } } while (next_permutation(v.begin(), v.end())); cout << mi << "\n"; for (auto u : ord) cout << u.se << " "; cout << "\n"; }