結果

問題 No.587 七対子
コンテスト
ユーザー pekempey
提出日時 2017-11-03 22:30:27
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 548 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 544 ms
コンパイル使用メモリ 89,752 KB
実行使用メモリ 97,716 KB
最終ジャッジ日時 2026-04-02 18:06:30
合計ジャッジ時間 1,451 ms
ジャッジサーバーID
(参考情報)
judge4_1 / judge5_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:35:11: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   35 |   cout << ans << endl;
      |           ^~~
main.cpp:17:8: note: 'ans' was declared here
   17 |   char ans;
      |        ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;

  vector<int> cnt(256);
  for (char c : s) {
    cnt[c]++;
  }

  char ans;
  int uniq = 0;
  for (int i = 0; i < 256; i++) {
    if (cnt[i] == 1) {
      ans = i;
    } else if (cnt[i] > 2) {
      cout << "Impossible" << endl;
      return 0;
    }
    if (1 <= cnt[i] && cnt[i] <= 2) {
      uniq++;
    }
  }
  if (uniq != 7) {
    cout << "Impossible" << endl;
    return 0;
  }

  cout << ans << endl;
}
0