結果
問題 | No.270 next_permutation (1) |
ユーザー |
![]() |
提出日時 | 2015-08-25 15:23:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 959 bytes |
コンパイル時間 | 403 ms |
コンパイル使用メモリ | 44,992 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-21 07:29:37 |
合計ジャッジ時間 | 1,352 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
コンパイルメッセージ
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; int rest; bool operator < (t i, t j){ return p[i.i] < p[j.i]; } void swap(t i, t j){ ans -= (ll)rest * std::abs(b[i.i] - p[i.i]); ans -= (ll)rest * std::abs(b[j.i] - p[j.i]); swap(p[i.i], p[j.i]); swap(i.i, j.i); ans += (ll)rest * std::abs(b[i.i] - p[i.i]); ans += (ll)rest * std::abs(b[j.i] - p[j.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){ rest = k - 1 - i; next_permutation(idx, idx + n); } printf("%lld\n", ans); return 0; }