結果
| 問題 | 
                            No.3032 ホモトピー入門
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ococonomy1
                         | 
                    
| 提出日時 | 2025-02-22 17:54:29 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 204 ms / 2,000 ms | 
| コード長 | 2,677 bytes | 
| コンパイル時間 | 2,449 ms | 
| コンパイル使用メモリ | 198,932 KB | 
| 実行使用メモリ | 45,396 KB | 
| 最終ジャッジ日時 | 2025-02-22 17:54:36 | 
| 合計ジャッジ時間 | 6,524 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define VEC_UNIQ(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define REV_PRIORITY_QUEUE(tp) priority_queue<tp,vector<tp>,greater<tp>>
#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる
    //添え字回りで面倒になりそうなときは楽になる言い換えを実装の前にじっくり考える
    //ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //g++ -D_GLIBCXX_DEBUG -O2 f.cpp -o o
    int n;
    cin >> n;
    int m;
    cin >> m;
    int ans = 0;
    while(n--){
        string s;
        cin >> s;
        vector<pii> point(1,pair(0,0));
        long double x = 0,y = 0;
        for(int i = 0; i < m; i++){
            if(s[i] == 'U')y += 1;
            if(s[i] == 'D')y -= 1;
            if(s[i] == 'L')x -= 1;
            if(s[i] == 'R')x += 1;
            point.push_back(pair(x,y));
        }
        for(int i = 0; i < m; i++){
            if(point[i].first >= 1)point[i].first = 1;
            if(point[i].first <= -1)point[i].first = -1;
            if(point[i].second >= 1)point[i].second = 1;
            if(point[i].second <= 0)point[i].second = 0;
        }
        point.push_back(pair(0,0));
        //for(int i = 0; i <= m; i++)cerr << point[i].first << ' ' << point[i].second << el;
        vector<pii> st;
        for(int i = 0; i <= m; i++){
            if((int)st.size() >= 1 && st.back() == point[i])continue;
            if((int)st.size() >= 2 && st[(int)st.size() - 2] == point[i]){
                st.pop_back(); continue;
            }
            st.push_back(point[i]);
        }
        if(st.size() == 1)ans++;
    }
    cout << ans << el;
    return;
}
void calc(void){
    return;
}
signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
            
            
            
        
            
ococonomy1