結果
| 問題 | No.345 最小チワワ問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-29 13:36:13 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 837 bytes |
| 記録 | |
| コンパイル時間 | 924 ms |
| コンパイル使用メモリ | 170,676 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:05:48 |
| 合計ジャッジ時間 | 1,633 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
33 | printf("%d\n",minLen == std::numeric_limits<std::string::size_type>::max() ? -1 : minLen);
| ~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| int long unsigned int
| %ld
ソースコード
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
int
main()
{
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::string s;
std::cin >> s;
std::stack<std::string::size_type> wposStack;
std::string::size_type minLen = std::numeric_limits<std::string::size_type>::max();
for (std::string::size_type i = s.length() - 1; i != static_cast<std::string::size_type>(-1); i--) {
switch (s[i]) {
case 'c':
if (wposStack.size() > 1) {
wposStack.pop();
minLen = std::min(minLen, wposStack.top() - i + 1);
wposStack.pop();
}
break;
case 'w':
wposStack.push(i);
break;
}
}
printf("%d\n",minLen == std::numeric_limits<std::string::size_type>::max() ? -1 : minLen);
return EXIT_SUCCESS;
}