結果
問題 | No.2745 String Swap Battle |
ユーザー |
![]() |
提出日時 | 2024-06-17 11:51:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,183 bytes |
コンパイル時間 | 1,150 ms |
コンパイル使用メモリ | 69,484 KB |
最終ジャッジ日時 | 2025-02-21 23:05:57 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:54:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:56:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 56 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-** 2745.cc: No.2745 String Swap Battle - yukicoder*/#include<cstdio>#include<string>#include<vector>#include<algorithm>using namespace std;/* constant */const int MAX_N = 100000;const int MAX_L = 100000;/* typedef */using vi = vector<int>;/* global variables */char s[MAX_L + 4];string ss[MAX_N];/* subroutines */void opr1(string &t) {int n = t.size();vi cvs[26];for (int i = 0; i < n; i++) cvs[t[i] - 'a'].push_back(i);for (int i = 0; i < n; i++) {int ti = t[i] - 'a';for (int c = 0; c < ti; c++)if (! cvs[c].empty() && i < cvs[c].back()) {swap(t[i], t[cvs[c].back()]);return;}}for (int c = 0; c < 26; c++)if (cvs[c].size() >= 2) return;swap(t[n - 2], t[n - 1]);}/* main */int main() {int n;scanf("%d", &n);for (int i = 0; i < n; i++) {scanf("%s", s);ss[i] = string(s);}string mint(1, 'z' + 1);int x = 0;for (int i = 0; i < n; i++) {opr1(ss[i]);if (mint > ss[i]) mint = ss[i], x = 1;else if (mint == ss[i]) x++;}for (int i = 0; i < n; i++)printf("%d\n", (mint == ss[i]) ? n + 1 - x : 0);return 0;}