Submission #892363

#TimeUsernameProblemLanguageResultExecution timeMemory
892363tradzMagneti (COCI21_magneti)C++14
30 / 110
1079 ms4696 KiB
#include <bits/stdc++.h> #define For(i,a,b) for(int i = a; i <= b; i++) #define Ford(i,a,b) for(int i = a; i >= b; i--) #define ll long long #define ii pair<int,int> #define fi first #define se second #define all(v) v.begin(),v.end() #define RRH(v) v.resize(unique(all(v)) - v.begin()) using namespace std; const int N = 1e6+7; const int M = 1e9+7; const ll oo = 3e18; ll gt[N], igt[N]; int n, l; ll poww(ll a, ll b) { if(b == 0) return 1; ll t = poww(a, b / 2); t = t * t % M; if(b & 1) t = t * a % M; return t; } ll ncr(ll nn, ll rr) { if (rr > nn || rr < 0) return 0; return ((gt[nn] * igt[rr]) % M * igt[nn - rr]) % M; } ii a[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); #define TASK "" if (fopen (".inp", "r")) { freopen (".inp", "r", stdin); freopen (".out", "w", stdout); } if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } cin >> n >> l; For(i, 1, n) cin >> a[i].fi, a[i].se = i; gt[0] = gt[1] = 1; For(i, 2, l) gt[i] = (i * gt[i - 1]) % M; igt[l] = poww(gt[l], M - 2); Ford(i, l - 1, 0) igt[i] = (igt[i + 1] * (i + 1)) % M; sort(a + 1, a + n + 1); ll ans = 0; if (a[1].fi == a[n].fi) { int tmp = l - (1 + a[1].fi * (n - 1)); cout << (ncr(n + tmp, tmp) * gt[n]) % M << "\n"; return 0; } do { int tmp = l - n; For(i, 2, n) tmp -= max(a[i - 1].fi - 1, a[i].fi - 1); ans = (ans + ncr(n + tmp, tmp)) % M; } while(next_permutation(a + 1, a + n + 1)); cout << ans << "\n"; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:40:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:41:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(TASK".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...