結果
問題 |
No.3183 Swap or Rotate
|
ユーザー |
![]() |
提出日時 | 2025-06-21 22:14:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1 ms / 1,000 ms |
コード長 | 866 bytes |
コンパイル時間 | 502 ms |
コンパイル使用メモリ | 42,100 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-21 22:14:02 |
合計ジャッジ時間 | 1,373 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:36:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:37:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | for (int i = 0; i < n; i++) scanf("%d", ps + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3183.cc: No.3183 Swap or Rotate - yukicoder */ #include<cstdio> #include<cassert> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 100; const int MAX_M = 20000; /* typedef */ /* global variables */ int ps[MAX_N]; char s[MAX_M + 16]; /* subroutines */ bool sorted(int n) { for (int i = 0; i + 1 < n; i++) if (ps[i] > ps[i + 1]) return false; return true; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", ps + i); int m = 0; while (! sorted(n)) { for (int i = 0; i + 1 < n; i++) { if (ps[i] > ps[i + 1]) swap(ps[i], ps[i + 1]), s[m++] = 'S'; s[m++] = 'R'; } s[m++] = 'R'; assert(m <= MAX_M); //for (int i = 0; i < n; i++) printf(" %d", ps[i]); putchar('\n'); } s[m] = '\0'; puts(s); return 0; }