結果
問題 | No.270 next_permutation (1) |
ユーザー |
![]() |
提出日時 | 2015-08-21 23:20:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 155 ms / 2,000 ms |
コード長 | 1,376 bytes |
コンパイル時間 | 949 ms |
コンパイル使用メモリ | 102,696 KB |
実行使用メモリ | 19,328 KB |
最終ジャッジ日時 | 2024-12-18 02:05:04 |
合計ジャッジ時間 | 2,445 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:69:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 69 | scanf("%d", &p[i]); | ~^ ~~~~~ | | | | | long long int* | int* | %lld main.cpp:72:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 72 | scanf("%d", &b[i]); | ~^ ~~~~~ | | | | | long long int* | int* | %lld main.cpp:67:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 67 | scanf("%d%d", &n, &k); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:69:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 69 | scanf("%d", &p[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:72:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 72 | scanf("%d", &b[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 100002int n;int k;long long int p[MAX];long long int b[MAX];bool visited[MAX];long long int dist = 0;long long int summ = 0;bool flag[MAX];set<int> s;set<int>::iterator ite;inline void dfs(int a){if (a == n){k--;summ += dist;return;}int be = 1;ite = s.begin();if (!visited[a]){be = p[a];ite = s.lower_bound(be);visited[a] = true;}for (; ite != s.end(); ite++){int i = (*ite);s.erase(ite);dist += (long long int)(abs(i - b[a]));dfs(a + 1);dist -= (long long int)(abs(i - b[a]));s.insert(i);ite = s.lower_bound(i);if (k == 0){return;}}}int main(){scanf("%d%d", &n, &k);for (int i = 0; i < n; i++){scanf("%d", &p[i]);}for (int i = 0; i < n; i++){scanf("%d", &b[i]);}for (int i = 1; i <= n; i++){s.insert(i);}int countt3 = 0;while (k){dfs(0);}printf("%lld\n", summ);return 0;}