結果
| 問題 |
No.397 NO MORE KADOMATSU
|
| コンテスト | |
| ユーザー |
moyashi_senpai
|
| 提出日時 | 2016-07-15 23:18:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,044 bytes |
| コンパイル時間 | 624 ms |
| コンパイル使用メモリ | 75,280 KB |
| 実行使用メモリ | 40,400 KB |
| 最終ジャッジ日時 | 2024-07-17 00:07:38 |
| 合計ジャッジ時間 | 7,122 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:72:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
72 | printf("%d\n", tesu);
| ~^ ~~~~
| | |
| int long long 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", &n);
| ~~~~~^~~~~~~~~~
main.cpp:69:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
69 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
main.cpp:76:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
76 | scanf("%*d");
| ~~~~~^~~~~~~
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
using namespace std;
#define Getsign(n) ((n > 0) - (n < 0))
typedef vector<int> Ivec;
typedef pair<int, int> Pos;
vector <pair<int, int>> history;
long long int tesu = 0;
/* 配列の要素を交換する */
void Swap(int x [], int i, int j)
{
int temp;
temp = x[i];
x[i] = x[j];
x[j] = temp;
history.push_back({i,j});
tesu++;
}
/* クイックソートを行う */
void QSort(int x [], int left, int right)
{
int i, j;
int pivot;
i = left; /* ソートする配列の一番小さい要素の添字 */
j = right; /* ソートする配列の一番大きい要素の添字 */
pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */
while (1) { /* 無限ループ */
while (x[i] < pivot) /* pivot より大きい値が */
i++; /* 出るまで i を増加させる */
while (pivot < x[j]) /* pivot より小さい値が */
j--; /* 出るまで j を減少させる */
if (i >= j) /* i >= j なら */
break; /* 無限ループから抜ける */
Swap(x, i, j); /* x[i] と x[j]を交換 */
i++; /* 次のデータ */
j--;
}
if (left < i - 1) /* 基準値の左に 2 以上要素があれば */
QSort(x, left, i - 1); /* 左の配列を Q ソートする */
if (j + 1 < right) /* 基準値の右に 2 以上要素があれば */
QSort(x, j + 1, right); /* 右の配列を Q ソートする */
}
int main() {
int n, a[100];
scanf("%d", &n);
for (int i = 0; n > i; i++) {
scanf("%d", &a[i]);
}
QSort(a, 0, n-1);
printf("%d\n", tesu);
for (int i = 0; tesu > i; i++) {
printf("%d %d\n", history[i].first, history[i].second);
}
scanf("%*d");
fflush(stdout);
return 0;
}
moyashi_senpai