답안 #992809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992809 2024-06-05T07:39:51 Z Uniq0rn Jetpack (COCI16_jetpack) C++14
80 / 80
18 ms 10328 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define pi pair<int,int>
#define sz(x) (int)x.size()

const int N = 1e5;
int n,flag;
char grid[10][N+10];
bool vis[10][N+10];
vector<int> ans;
void dfs(int i,int j){
    if(flag || vis[i][j] || grid[i][j] == 'X') return ;
    vis[i][j] = 1;
    if(j == n-1){
        flag = 1;
        if(sz(ans)%2){
            if(ans.back() == n-1) ans.pop_back();
            else ans.push_back(n-1);
        }
        cout << sz(ans)/2 << '\n';
        for(int i=0;i<sz(ans)-1;i+=2){
            cout << ans[i] << ' ' << ans[i+1]-ans[i] << '\n';
        }
        return ;
    }
    if(i == 9){
        dfs(i,j+1);
        ans.push_back(j);
        dfs(i-1,j+1);
        ans.pop_back();
    }
    else if(i == 0){
        dfs(i,j+1);
        ans.push_back(j);
        dfs(i+1,j+1);
        ans.pop_back();
    }
    else{
        //cout << i << ' ' << j << '\n';
        int now = sz(ans);
        if(sz(ans)%2 == 0) ans.push_back(j);
        dfs(i-1,j+1);
        if(sz(ans)-now >= 0 && (sz(ans)-now)%2 == 1) ans.pop_back();
        now = sz(ans);
        if(sz(ans)%2 == 1) ans.push_back(j);
        dfs(i+1,j+1);
        if(sz(ans)-now >= 0 && (sz(ans)-now)%2 == 1) ans.pop_back();
    }
}
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    for(int i=0;i<10;i++){
        for(int j=0;j<n;j++){
            cin >> grid[i][j];
        }
    }
    dfs(9,0);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 936 KB Output is correct
6 Correct 2 ms 1116 KB Output is correct
7 Correct 3 ms 2396 KB Output is correct
8 Correct 8 ms 5208 KB Output is correct
9 Correct 12 ms 7516 KB Output is correct
10 Correct 18 ms 10328 KB Output is correct