結果
| 問題 |
No.270 next_permutation (1)
|
| ユーザー |
y_mazun
|
| 提出日時 | 2015-08-21 23:23:11 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 860 bytes |
| コンパイル時間 | 540 ms |
| コンパイル使用メモリ | 45,124 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 12:14:02 |
| 合計ジャッジ時間 | 1,412 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:9:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#include <algorithm>
#include <cstdlib>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
typedef long long ll;
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
struct t{
int i;
t(){}
};
int p[100000];
int b[100000];
t idx[100000];
ll ans;
bool operator < (t i, t j){
return p[i.i] < p[j.i];
}
void swap(t i, t j){
ans -= std::abs(b[i.i] - p[i.i]);
ans -= std::abs(b[j.i] - p[j.i]);
swap(i.i, j.i);
ans += std::abs(b[i.i] - p[j.i]);
ans += std::abs(b[j.i] - p[i.i]);
}
int main(){
const int n = getInt();
const int k = getInt();
REP(i,n) p[i] = getInt();
REP(i,n) b[i] = getInt();
REP(i,n) idx[i].i = i;
REP(i,n) ans += (ll)k * std::abs(p[i] - b[i]);
REP(i,k-1){
next_permutation(idx, idx + n);
}
printf("%lld\n", ans);
return 0;
}
y_mazun