結果
| 問題 |
No.270 next_permutation (1)
|
| コンテスト | |
| ユーザー |
Kmcode1
|
| 提出日時 | 2015-08-21 23:13:00 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,199 bytes |
| コンパイル時間 | 761 ms |
| コンパイル使用メモリ | 92,952 KB |
| 実行使用メモリ | 13,184 KB |
| 最終ジャッジ日時 | 2024-07-18 12:09:05 |
| 合計ジャッジ時間 | 5,468 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 TLE * 1 -- * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
65 | scanf("%d", &p[i]);
| ~^ ~~~~~
| | |
| | long long int*
| int*
| %lld
main.cpp:68:25: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
68 | scanf("%d", &b[i]);
| ~^ ~~~~~
| | |
| | long long int*
| int*
| %lld
main.cpp:63:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%d%d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:65:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | scanf("%d", &p[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:68:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
68 | 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>
using namespace std;
#define MAX 100002
int 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];
inline void dfs(int a){
if (a == n){
k--;
summ += dist;
return;
}
int be = 1;
if (!visited[a]){
be = p[a];
visited[a] = true;
}
for (int i = be; i <= n; i++){
if (flag[i]){
continue;
}
flag[i] = true;
dist += (long long int)(abs(i - b[a]));
dfs(a + 1);
dist -= (long long int)(abs(i - b[a]));
flag[i] = false;
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]);
}
while (k){
dfs(0);
}
printf("%lld\n", summ);
return 0;
}
Kmcode1