結果

問題 No.2373 wa, wo, n
ユーザー Yoyoyo8128Yoyoyo8128
提出日時 2023-07-07 23:00:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 8,674 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 213,972 KB
実行使用メモリ 62,872 KB
最終ジャッジ日時 2023-09-29 00:36:53
合計ジャッジ時間 5,800 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 51 ms
33,592 KB
testcase_15 AC 10 ms
8,128 KB
testcase_16 AC 55 ms
36,484 KB
testcase_17 AC 16 ms
12,316 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 29 ms
17,572 KB
testcase_20 AC 57 ms
37,804 KB
testcase_21 AC 26 ms
16,840 KB
testcase_22 AC 42 ms
25,816 KB
testcase_23 AC 66 ms
43,612 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 62 ms
40,704 KB
testcase_33 AC 71 ms
47,364 KB
testcase_34 AC 96 ms
62,872 KB
testcase_35 AC 19 ms
16,348 KB
testcase_36 AC 45 ms
32,764 KB
testcase_37 AC 39 ms
31,400 KB
testcase_38 AC 50 ms
37,792 KB
testcase_39 AC 29 ms
25,200 KB
testcase_40 AC 51 ms
35,688 KB
testcase_41 AC 52 ms
35,744 KB
testcase_42 AC 84 ms
56,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const string Yes="Yes";
const string No="No";
const string YES="YES";
const string NO="NO";
const string abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD=1000000007;
const ll mod=998244353;
const long long INF = 1LL << 60;
const long double PI=3.141592653589793;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define inV(vec) for(ll i=0;i<vec.size();i++)cin>>vec[i];
#define outV(vec) for(ll i=0;i<vec.size();i++){cout<<vec[i]<<" ";}cout<<endl;
#define print(s) cout<<s<<endl;
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }


//DFS
map<ll,vector<int>>Gra;
map<ll,ll>visited;// false=not visited, true=visited
ll hen=0;
void DFS(int pos){
  visited[pos]=true;
  for(int i : Gra[pos]){
    if(visited[i]==false)DFS(i);
  }
}

//BFS
const vector<int>dx = {0, 1, 0, -1};
const vector<int>dy = {1, 0, -1, 0};
vector<vector<int>> BFS(int H, int W, const vector<string> &G, pair<int, int> s) {
    vector<vector<int>> dist(H, vector<int>(W, -1));  //すべての頂点を未訪問に初期化
    queue<pair<int, int>> que;

    //初期条件 (頂点sを初期頂点とする)
    dist[s.first][s.second] = 0;
    que.push(s);  // sを探索済み頂点に

    // BFS開始
    while (!que.empty()) {
        pair<int, int> v = que.front();
        que.pop();

        //頂点vからたどれる頂点を全て調べる
        for (int i = 0; i < 4; i++) {
            int X = dx[i] + v.first;
            int Y = dy[i] + v.second;
            if (X < 0 || X >= H || Y < 0 || Y >= W) continue;
            //すでに発見済みの頂点は探索しない
            if (dist[X][Y] != -1 || G[X][Y] == '#') continue;

            //新たな未探索点xについて距離情報を更新してキューに挿入
            dist[X][Y] = dist[v.first][v.second] + 1;
            que.push(make_pair(X, Y));
        }
    }
    return dist;
}

//エラトステネスの篩
vector<bool>Prime(2,false);//false=not Prime number, true=Prime Number
void Era(ll N){
  for(ll i=0;i<N-1;i++){
    Prime.pb(true);
  }
  for(ll i=2;i*i<=N;i++){
    if(Prime[i]){
      for(ll x=2*i;x<=N;x+=i)Prime[x]=false;
    }
  }
}

//繰り返し二乗法
ll modpow(ll a, ll n, ll mod) {
    if(a==0){
        return 0;
    }
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//素因数分解
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

//割り算
ll Div(ll a,ll b,ll m){
  return (a * modpow(b,m-2,m)) % m;
}

//階乗
vector<ll>fact(1);
void fac(ll N,ll m){
  fact[0]=1;
  for(int i=1;i<=N;i++){
    fact.pb(fact[i-1]*(i));
    fact[i]%=m;
  }
}

//組み合わせ
ll comb(ll n,ll r,ll m){
  return Div(fact[n],fact[r] * fact[n-r] % m,m);
}

//UnionFind
struct UnionFind {
    vector<int> par, rank, siz;

    // 構造体の初期化
    UnionFind(int n) : par(n,-1), rank(n,0), siz(n,1) { }

    // 根を求める
    int root(int x) {
        if (par[x]==-1) return x; // x が根の場合は x を返す
        else return par[x] = root(par[x]); // 経路圧縮
    }

    // x と y が同じグループに属するか (= 根が一致するか)
    bool same(int x, int y) {
        return root(x)==root(y);
    }

    // x を含むグループと y を含むグループを併合する
    bool unite(int x, int y) {
        int rx = root(x), ry = root(y); // x 側と y 側の根を取得する
        if (rx==ry) return false; // すでに同じグループのときは何もしない
        // union by rank
        if (rank[rx]<rank[ry]) swap(rx, ry); // ry 側の rank が小さくなるようにする
        par[ry] = rx; // ry を rx の子とする
        if (rank[rx]==rank[ry]) rank[rx]++; // rx 側の rank を調整する
        siz[rx] += siz[ry]; // rx 側の siz を調整する
        return true;
    }

    // x を含む根付き木のサイズを求める
    int size(int x) {
        return siz[root(x)];
    }
};
//https://algo-method.com/descriptions/136

//ダイクストラ
struct Edge {
    long long to;
    long long cost;
};
void dijkstra(const vector<vector<Edge>> &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        pair<long long, int> p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}
//https://algo-logic.info/dijkstra/

//ワーシャルフロイド
void warshall_floyd(vector<vector<long long>> &dist) {
    for (int k = 0; k < (int)dist.size(); k++) {
        for (int i = 0; i < (int)dist.size(); i++) {
            for (int j = 0; j < (int)dist.size(); j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}
//https://qiita.com/okaryo/items/8e6cd73f8a676b7a5d75


//計算幾何学

//ベクトル B-A
pair<long long,long long> bector(pair<long long,long long> A,pair<long long,long long> B){
    return mp(B.first - A.first , B.second - A.second);
}

//内積(a,bはベクトル)、内積は90度が0で角度が小さいほど大きい
ll inner(pair<long long,long long> a,pair<long long,long long> b){
    return a.first*b.first+a.second+b.second;
}

//外積(a,bはベクトル)、反時計だと負、時計だと正
ll outer(pair<long long,long long> a,pair<long long,long long> b){
    return a.first*b.second-a.second*b.first;
}

long long merge_cnt(vector<long long> &a) {
    long long n = a.size();
    if (n <= 1) return 0; 
    long long cnt = 0;
    vector<long long> b(a.begin(), a.begin()+n/2);
    vector<long long> c(a.begin()+(n/2), a.end());
    cnt += merge_cnt(b);
    cnt += merge_cnt(c);
    long long ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

/*UnionFindはUnionFind uf(頂点の数)と書こう uniteは合併 sameが判定 sizeがサイズ
    セグ木をやれ!!
    I am a cyan coder.
    精進しろ!!
*/
ll manhattan(pll A,pll B){
    return(abs(A.fi-B.fi)+abs(A.se-B.se));
}

int main(){
    ll N;
    string s;
    cin>>N>>s;
    vector<map<char,ll>>dp(N);
    if(s[0]=='?' || s[0]=='w'){
            
                dp[0]['w']=true;
            
        }
        if(s[0]=='?' || s[0]=='n'){

                dp[0]['n']=true;
            
        }
    for(int i=1;i<N;i++){
        if(s[i]=='?' || s[i]=='a'){
            if(dp[i-1]['w']){
                dp[i]['a']=true;
            }
        }
        if(s[i]=='?' || s[i]=='o'){
            if(dp[i-1]['w']){
                dp[i]['o']=true;
            }
        }
        if(s[i]=='?' || s[i]=='w'){
            if(dp[i-1]['n'] || dp[i-1]['a'] || dp[i-1]['o']){
                dp[i]['w']=true;
            }
        }
        if(s[i]=='?' || s[i]=='n'){
            if(dp[i-1]['n'] || dp[i-1]['a'] || dp[i-1]['o']){
                dp[i]['n']=true;
            }
        }
    }
    YesNo(dp[N-1]['a'] || dp[N-1]['o'] || dp[N-1]['n']);
}
0