結果

問題 No.345 最小チワワ問題
ユーザー GeckoCPPSonataGeckoCPPSonata
提出日時 2019-09-01 01:03:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 6,582 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 110,444 KB
最終ジャッジ日時 2025-01-07 16:14:59
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

//gcc
//#include <bits/stdc++.h>
//clang
#include <set> //*********************************************************
#include <map> //*********************************************************
#include <list> //*********************************************************
#include <queue> //*********************************************************
#include <stack> //** **************************************************
#include <cmath> //** *** **************************************************
#include <ctime> //** *** ********************************************
#include <cstdio> //** ********* ********************************************
#include <vector> //** ** * ********************************************
#include <string> //** **** * * ********************************************
#include <bitset> //** ** * * * *************************************
#include <cctype> //** * * * ****** * ************************************
#include <cstdlib> //**** * * ** ************************************
#include <cstring> //**** ************ ** *********************************
#include <utility> //* * *********************************************
#include <numeric> //* ******* * * *************************************
#include <complex> //* * * * * ***** *************************************
#include <sstream> //* * ***** * * * * *************************************
#include <fstream> //* * * * *** * * *************************************
#include <iomanip> //* * *** *** *** * *************************************
#include <cassert> //* * * *** * * *************************************
#include <iostream> //* *** *** ***** * ***************************************
#include <iterator> //* * * *******************************
#include <algorithm>//*********************************************************
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
const char alphabetl[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
    'y', 'z'};
const char alphabetu[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
    'Y', 'Z'};
static const double EPS = 1e-14;
static const ll INFLL = 1e18;
static const int INF = (1 << 30) - 1;
static const ll MOD = (ll) 1e9 + 7;
const int NM = 101001;//max index of array
int dp[NM];
#define cauto const auto&
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define itn int
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(n-1); i>=0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define FOREQ(i,a,b) for(int i=a; i<=(int)(b); i++)
#define RFOR(i,a,b) for(int i=a; i>(int)(b); i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define PRINT(n) cout << n << "\n";
#define PRINT2(n, m) cout << n << " " << m << " "<< "\n";
#define IN(a, x, b) (a<=x && x<b)
#define pb push_back
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
const ll MAX_V = 1010;
const ll MAX_E = 2010;
ll V, E;
struct edge {
ll from, to, cost;
};
edge ES[MAX_E];
ll d[MAX_V];
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
/** example)
showElem(5, 2340182213LL) === false
showElem(8, 8327237484LL) === true
**/
bool showElem(int n, ll target) {
if (9 < n) {
return false;
}
string s = to_string(target);
bool is = false;
for(int i = 0; i < s.size(); i++) {
if (s[i] == char(n + '0')){
is = true;
break;
}
}
return is;
}
void precalc() {
/*
for (int i = 2; i < C; ++i) {
if (!least_prime[i]) {
least_prime[i] = i;
for (li j = i * 1LL * i; j < C; j += i) {
least_prime[j] = i;
}
}
}
*/
/*
fact[0] = revfact[0] = 1;
for (int i = 1; i < 100500; ++i) {
fact[i] = fact[i - 1] * i % curMod;
revfact[i] = binpow(fact[i], curMod - 2, curMod);
}
*/
/*
for (int w = 0; w < 2; ++w) {
powers[w][0] = 1;
for (int j = 1; j < C; ++j) {
powers[w][j] = (powers[w][j - 1] * 1LL * pr[w]) % mods[w];
}
}
*/
/*
catalan[0] = 1;
for (int n = 0; n < 200500 - 1; ++n) {
catalan[n + 1] = catalan[n] * 2 * (2 * n + 1) % MOD * binpow(n + 2, MOD - 2, MOD) % MOD;
}
*/
/*
for (int i = 0; i < 5010; ++i) {
c[i][i] = c[i][0] = 1;
for (int j = 1; j < i; ++j) {
c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
}
}
*/
/*
for (int i = 0; i < 100; ++i) {
doubleC[i][i] = doubleC[i][0] = 1.0;
for (int j = 1; j < i; ++j) {
doubleC[i][j] = doubleC[i - 1][j - 1] + doubleC[i - 1][j];
}
}
*/
}
void Main();
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
}
void Main(){
// Write your source code Here...
string s;
cin >> s;
int n = SZ(s);
int ans = INF;
int w1 = n, w2 = n;
rrep(i, n) {
if (s[i] == 'w') {
w2 = w1;
w1 = i;
}
if (s[i] == 'c' && w2 != n) {
ans = min(ans, w2 - i + 1);
}
}
if (ans == INF) ans = -1;
PRINT(ans)
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0