Submission #1058954

#TimeUsernameProblemLanguageResultExecution timeMemory
1058954ThanhsMagneti (COCI21_magneti)C++14
20 / 110
1070 ms624 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define fi first #define se second #define all(x) x.begin(), x.end() // mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); // int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 4e5 + 5; const int LM = 1e4 + 5; const int mod = 1e9 + 7; struct mi { int v; mi() : v(0){} mi(int v) : v(v) { if (v >= mod) v -= mod; } mi operator+(const mi& o) { return mi(v + o.v); } mi operator-(const mi& o) { return mi(v + mod - o.v); } mi operator*(const mi& o) { return mi(1ll * v * o.v % mod); } mi& operator+=(const mi &o) { v += o.v; if (v >= mod) v -= mod; return *this; } mi& operator-=(const mi &o) { v += mod - o.v; if (v >= mod) v -= mod; return *this; } mi& operator*=(const mi& o) { v = 1ll * v * o.v % mod; return *this; } }fact[LM], invfact[LM]; mi C(int n, int k) { if (k < 0 || k > n) return mi(0); return fact[n] * invfact[k] * invfact[n - k]; } int n, k, a[NM]; vector<int> p; mi bp(mi x, int y) { mi res(1); while (y) { if (y & 1) res = res * x; x = x * x; y >>= 1; } return res; } void pre() { fact[0].v = 1; for (int i = 1; i < LM; i++) fact[i] = fact[i - 1] * mi(i); invfact[LM - 1] = bp(fact[LM - 1], mod - 2); for (int i = LM - 1; i >= 1; i--) invfact[i - 1] = invfact[i] * mi(i); } void solve() { if (n > 10) return; pre(); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i]--; } for (int i = 1; i <= n; i++) p.push_back(i); mi ans(0); do { int t = k; for (int i = 0; i < n - 1; i++) t -= max(a[p[i]], a[p[i + 1]]); ans += C(t, n); }while(next_permutation(p.begin(), p.end())); cout << ans.v; } signed main() { fastIO if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int tc = 1; // cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen("out.txt", "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...