뜌릅

Photoshoot 18323번 [백준] 본문

알고리즘/PS 문제

Photoshoot 18323번 [백준]

TwoCastle9 2022. 11. 11. 10:30
반응형

 

 

https://www.acmicpc.net/problem/18323

 

18323번: Photoshoot

Farmer John is lining up his $N$ cows ($2\le N\le 10^3$), numbered $1\ldots N$, for a photoshoot. FJ initially planned for the $i$-th cow from the left to be the cow numbered $a_i,$ and wrote down the permutation $a_1,a_2,\ldots,a_N$ on a sheet of paper. U

www.acmicpc.net

 

 

#include<bits/stdc++.h>


using namespace std;
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, j) for(ll i=0;i<j;i++)
typedef long long ll;

const int MAXN = 510;
const int MAXINT = 2147483098;
const int inf = 1e9 + 7;
const int MOD = 1e9;

void solve() {
    int n;
    cin >> n;
    vector<int> v1(n - 1, 0);
    set<int> v2;
    int ret;
    for (auto &x: v1)cin >> x;

    for (int i = v1[0] - 1; i >= 1; i--) {
        bool ans = true;
        v2.clear();
        v2.insert(i);
        auto temp = v1[0] - i;
        for(int j = 1; j< n; j++){
            if(temp <= 0)ans =false;
           if(v2.find(temp) != v2.end())
               ans = false;
           v2.insert(temp);
           temp = v1[j] - temp;
        }
        if(ans){
            ret = i;
            rep(j,n-1){
                cout<<ret<<" ";
                ret = v1[j] - ret;
            }
            cout<<ret;
        }
    }
}

int main() {
    solve();
    return 0;
}
반응형

'알고리즘 > PS 문제' 카테고리의 다른 글

대표 자연수 2548번 [백준]  (0) 2022.11.16
귀찮아 14929번 [백준]  (0) 2022.11.12
아기상어 16236번 [백준]  (2) 2022.09.03
테트로미노 14500번 [백준]  (0) 2022.09.02
외판원 순회3 16991번 [백준]  (0) 2022.09.01