Submission #754680

#TimeUsernameProblemLanguageResultExecution timeMemory
754680marvinthangGondola (IOI14_gondola)C++17
60 / 100
19 ms2188 KiB
/************************************* * author: marvinthang * * created: 08.06.2023 17:22:12 * *************************************/ #include "gondola.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i--; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } // end of template void shift(int n, int seq[]) { REP(i, n) if (seq[i] <= n) { rotate(seq, seq + (i - seq[i] + 1 + n) % n, seq + n); return; } } int valid(int n, int inputSeq[]) { shift(n, inputSeq); REP(i, n) if (inputSeq[i] <= n && inputSeq[i] != i + 1) return 0; sort(inputSeq, inputSeq + n); REP(i, n - 1) if (inputSeq[i] == inputSeq[i + 1]) return 0; return 1; } int replacement(int n, int gondolaSeq[], int replacementSeq[]) { shift(n, gondolaSeq); int ma = *max_element(gondolaSeq, gondolaSeq + n); vector <int> pos(ma + 1, -1); REP(i, n) pos[gondolaSeq[i]] = i; REPD(i, ma) if (pos[i] == -1) pos[i] = pos[i + 1]; REP(i, n) gondolaSeq[i] = i + 1; int cnt = 0; FORE(i, n + 1, ma) { replacementSeq[i - n - 1] = gondolaSeq[pos[i]]; gondolaSeq[pos[i]] = i; } return ma - n; } const int MOD = 1e9 + 7; void mul(int &a, int b) { a = 1LL * a * b % MOD; } int POW(int a, int b) { int res = 1; for (; b; b >>= 1) { if (b & 1) mul(res, a); mul(a, a); } return res; } int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; int res = 1; REP(i, n) if (inputSeq[i] > n) mul(res, POW(n - i, inputSeq[i] - (i ? max(inputSeq[i - 1], n) : n) - 1)); if (inputSeq[0] > n) mul(res, n); return res; } #ifdef LOCAL #include <stdio.h> #include <assert.h> #include "gondola.h" int gondolaSequence[100001]; int replacementSequence[250001]; int main() { file("gondola"); int i, n, tag; int nr; assert(scanf("%d", &tag)==1); assert(scanf("%d", &n)==1); for(i=0;i< n;i++) assert( scanf("%d", &gondolaSequence[i]) ==1); switch (tag){ case 1: case 2: case 3: printf("%d\n", valid(n, gondolaSequence)); break; case 4: case 5: case 6: nr = replacement(n, gondolaSequence, replacementSequence); printf("%d ", nr); if (nr > 0) { for (i=0; i<nr-1; i++) printf("%d ", replacementSequence[i]); printf("%d\n", replacementSequence[nr-1]); } else printf("\n"); break; case 7: case 8: case 9: case 10: printf("%d\n", countReplacement(n, gondolaSequence)); break; } return 0; } #endif

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:68:9: warning: unused variable 'cnt' [-Wunused-variable]
   68 |     int cnt = 0;
      |         ^~~
#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...
#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...