結果
問題 | No.271 next_permutation (2) |
ユーザー | Kmcode1 |
提出日時 | 2015-08-22 00:17:53 |
言語 | C++11 (gcc 11.4.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,326 bytes |
コンパイル時間 | 853 ms |
コンパイル使用メモリ | 101,044 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-18 12:27:14 |
合計ジャッジ時間 | 3,493 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:103:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 103 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:104:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 104 | scanf("%lld", &K); | ~~~~~^~~~~~~~~~~~ main.cpp:106:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 106 | scanf("%d", &p[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cctype> #include<cstdlib> #include<algorithm> #include<bitset> #include<vector> #include<list> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<sstream> #include<fstream> #include<iomanip> #include<ctime> #include<complex> #include<functional> #include<climits> #include<cassert> #include<iterator> #include<unordered_set> using namespace std; #define MAX 100002 int n; long long int K; int p[MAX]; long long int k[MAX]; //fac /*get_inv*/ int a[MAX]; #define MOD 1000000007LL long long int re = 0; int bit[MAX]; long long int ppow(long long int i, long long int j){ long long int res = 1LL; while (j){ if (j & 1LL){ res *= i; if (res >= MOD){ res %= MOD; } } i *= i; i %= MOD; j >>= 1LL; } return res; } long long int inv[MAX]; void add(int i, int x){ i++; while (i < MAX){ bit[i] += x; i += i&-i; } } int sum(int i){ int r = 0; i++; while (i){ r += bit[i]; i -= i&-i; } return r; } inline void dfs(int b){ if (b == n){ return; } dfs(b + 1); re += (long long int)(sum(a[b])); long long int rest = n - b; long long int pr = rest*(rest - 1LL); pr %= MOD; pr *= inv[rest]; if (pr >= MOD){ pr %= MOD; } pr *= (long long int)(a[b] - 1); re += pr; if (re >= MOD){ re %= MOD; } add(a[b], 1); for (int i = a[b] -1; i >= 1; i--){ re += (long long int)(sum(i)); if (re >= MOD){ re %= MOD; } } } long long int calc(){ re = 0; memset(bit, 0, sizeof(bit)); dfs(0); return re; } int main(){ scanf("%d", &n); scanf("%lld", &K); for (int i = 0; i < n; i++){ scanf("%d", &p[i]); } memset(k, -1, sizeof(k)); k[0] = 1LL; for (int i = 1; i < MAX; i++){ k[i] = k[i - 1]; k[i] *= (long long int)(i); k[i] %= MOD; } long long int P2 = ppow(2, MOD - 2); for (int i = 2; i < MAX; i++){ inv[i] = k[i] * P2; inv[i] %= MOD; } for (int i = 0; i < n; i++){ a[i] = k[i]; } long long int ANS = 0; calc(); ANS += MOD - re; if (ANS >= MOD){ ANS %= MOD; } bool exten = false; long long int ss = 1LL; for (int i = 1; i <= n; i++){ ss *= (long long int)(i); if (ss > K){ exten = true; break; } } if (exten){ for (int i = n; i >= 1; i--){ a[n - i] = i; } calc(); } else{ } return 0; }