結果
問題 | No.2715 Unique Chimatagram |
ユーザー |
![]() |
提出日時 | 2024-04-30 14:01:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,311 bytes |
コンパイル時間 | 352 ms |
コンパイル使用メモリ | 41,984 KB |
最終ジャッジ日時 | 2025-02-21 09:53:26 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:49:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:53:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | scanf("%s", s); | ~~~~~^~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2715.cc: No.2715 Unique Chimatagram - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_L = 10; /* typedef */ /* global variables */ int cs[MAX_N][26], ls[MAX_N]; /* subroutines */ int anagram(char s[], int cs[]) { int l = 0; for (int i = 0; s[i]; i++) cs[s[i] - 'a']++, l++; return l; } bool chimata(int i, int j) { bool f = true; if (ls[i] != ls[j] + 1) f = false; else { int k1 = 0; for (int a = 0; f && a < 26; a++) { if (cs[i][a] == cs[j][a] + 1) k1++; else if (cs[i][a] != cs[j][a]) f = false; } f = (f && (k1 == 1)); } //printf(" chimate(%d,%d)=%d\n", i, j, f); return f; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char s[MAX_L + 4]; scanf("%s", s); ls[i] = anagram(s, cs[i]); } for (int i = 0; i < n; i++) for (int a = 0; a < 26; a++) { cs[i][a]++, ls[i]++; bool ok = false; for (int j = 0; ! ok && j < n; j++) if (i != j) ok = chimata(i, j); if (! ok) { for (int k = 0; k < 26; k++) for (int c = 0; c < cs[i][k]; c++) putchar('a' + k); putchar('\n'); return 0; } cs[i][a]--, ls[i]--; } puts("-1"); return 0; }