본문 바로가기
알고리즘/Codeforces

Codeforces Round #656 (Div. 3) ABC

by 유시은 2020. 8. 6.
#include <iostream>
#include <algorithm>
using namespace std;
 
int T, x, y, z;
int a[3];
 
int main() {
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(0);
 
    cin >> T;
    while (T--) {
        cin >> a[0] >> a[1] >> a[2];
        sort(a, a + 3);
 
        if (a[1] != a[2]) {
            cout << "NO\n";
            continue;
        }
        x = a[2];
        y = a[0];
        z = a[0];
        cout << "YES\n" << x << " " << y << " " << z << "\n";
    }
 
    return 0;
}

 

A - Three Pairwise Maximums

 

from sys import stdin
T = int(stdin.readline())
li = []
for _ in range(T):
    garb = stdin.readline()
    li = [int(x) for x in stdin.readline().split()]
    se = set(li)
    for elem in li:
        if elem in se:
            se.remove(elem)
            print(elem,end=" ")
    print()

 

B - Restore the Permutation by Merger

 

#include <iostream>
#include <algorithm>
using namespace std;
 
int T, N;
int a[200000];
 
bool issorted(int arr[], int len) {
    if (len < 2) return true;
    for (int i = 1; i < len; ++i) {
        if (arr[i - 1] > arr[i]) return false;
    }
    return true;
}
 
int main() {
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(0);
 
    cin >> T;
    while (T--) {
        cin >> N;
        for (int i = 0; i < N; ++i) {
            cin >> a[i];
        }
        if (N == 1) { cout << "0\n"; continue; }
 
        short slope = 0; // 마지막 수 기준으로 오르막 내리막, 평지라면 0
        int high = 0;
 
        for (int i = N - 1; i > 0; --i) {
            if (slope == 0) {
                if (a[i] > a[i - 1]) slope = -1;
                else if (a[i] < a[i - 1]) slope = 1;
            }
            else if (slope == -1) {
                if (a[i] < a[i - 1]) { high = i; break; }
            }
            else if (slope == 1) {
                if (a[i] > a[i - 1]) { high = i; break; }
            }
        }/*
        cout << "slope: " << slope << endl;
        cout << "high: " << high << endl;*/
        if (slope == 0) { cout << "0\n"; continue; }
        for (int i = high; i > 0; --i) {
            high = i;
            if (a[i] < a[i - 1]) break;
            if (high == 1) high = 0;
        }
        cout << high << "\n";
    }
 
    return 0;
}

 

C - Make It Good

댓글