結果

問題 No.345 最小チワワ問題
ユーザー AQUA16573837AQUA16573837
提出日時 2018-03-12 02:10:13
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 42,968 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 12:13:18
合計ジャッジ時間 1,303 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         scanf("%s", s);
      |         ~~~~~^~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <deque>
using namespace std;
using ll = long long;

int main() {
	char s[101] = { 0 };
	scanf("%s", s);
	int mins = 1000;
	deque<int> c, w;
	for (int i = 0; s[i] != 0; i++) {
		if (s[i] == 'c')
			c.emplace_back(i);
		if (s[i] == 'w') {
			if (2 <= w.size())
				w.pop_front();
			w.emplace_back(i);

			while (2 <= c.size() && c[1] < w[0])
				c.pop_front();
			if (1 <= c.size() && 2 <= w.size() && c[0] < w[0])
				mins = min(mins, w[1] - c[0] + 1);
		}
	}
	printf("%d\n", mins != 1000 ? mins : -1);
}
0