Strong Root

난이도 ☆☆☆☆☆


문제를 보시려면 여기를 클릭


이하는 코드입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string>
#include <iostream>
 
#pragma warning(disable:4996)
 
using namespace std;
 
int main() {
    int C;
    scanf("%d\n", &C);
 
    for (int i = 0; i < C; i++) {
        string input;
        getline(cin, input);
 
        cout << "Hello, " << input << "!" << endl;
    }
 
    return 0;
}
cs

문제를 보시려면 여기를 클릭


이하는 코드입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <string.h>
 
#pragma warning(disable:4996)
 
#define NO 0
#define YES 1
 
int cache[101][101];
int board[101][101];
int n;
 
int canReach(int y, int x) {
    if ((y > n - 1) || (x > n - 1)) {
        return NO;
    }
 
    int& ret = cache[y][x];
    if (ret != -1) {
        return ret;
    }
 
    int amount = board[y][x];
    return ret = (canReach(y + amount, x) || canReach(y, x + amount));
}
 
int main() {
    int C;
    scanf("%d", &C);
 
    for (int i = 0; i < C; i++) {
        scanf("%d", &n);
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < n; k++) {
                scanf("%d", &board[j][k]);
            }
        }
 
        memset(cache, -1sizeof(cache));
        cache[n - 1][n - 1] = YES;
        int ret = canReach(00);
        if (ret == YES) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
 
    return 0;
}
cs

문제를 보시려면 여기를 클릭


이하는 코드입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <stdio.h>
 
#pragma warning(disable:4996)
 
typedef struct Person {
    int id;
    struct Person *next;
} Person;
 
typedef struct {
    Person *last;
    Person *beforeTarget;
    int size;
} List;
 
List *list;
int N, K;
 
void pushBack(int id) {
    Person *newPerson = new Person;
    newPerson->id = id;
    
    if (list->size == 0) {
        newPerson->next = NULL;
    }
    else if (list->size == 1) {
        newPerson->next = list->last;
        list->last->next = newPerson;
    }
    else {
        // new person -> first
        Person *first = list->last->next;
        newPerson->next = first;
 
        // old last -> new person
        list->last->next = newPerson;
    }
 
    // new last = new person
    list->last = newPerson;
 
    list->size++;
}
 
void killTarget() {
    if (list->size <= 2) {
        return;
    }
 
    Person *target = list->beforeTarget->next;
    
    // before target -> target's next
    list->beforeTarget->next = target->next;
 
    // set list's beforeTarget
    Person *temp = list->beforeTarget;
    for (int i = 0; i < K - 1; i++) {
        temp = temp->next;
    }
    list->beforeTarget = temp;
 
    // remove target
    delete(target);
    list->size--;
 
    // recursive call
    killTarget();
}
 
int main() {
    int C;
    scanf("%d", &C);
 
    for (int i = 0; i < C; i++) {
        scanf("%d %d", &N, &K);
 
        list = new List;
        list->size = 0;
        
        for (int j = 0; j < N; j++) {
            pushBack(j + 1);
        }
 
        list->beforeTarget = list->last;
        killTarget();
 
        int id1 = list->beforeTarget->id;
        int id2 = list->beforeTarget->next->id;
 
        if (id1 < id2) {
            printf("%d %d\n", id1, id2);
        }
        else {
            printf("%d %d\n", id2, id1);
        }
 
        delete(list);
    }
 
    return 0;
}
cs


문제를 보시려면 여기를 클릭


이하는 코드입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <queue>
 
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
 
#pragma warning(disable:4996)
 
using namespace std;
 
typedef struct {
    int number;
    int length;
} Cache;
 
struct Compare {
    bool operator() (Cache left, Cache right) {
        return left.length < right.length;
    }
};
 
int N;
int board[501];
 
int main() {
    int C;
    scanf("%d", &C);
 
    for (int i = 0; i < C; i++) {
        scanf("%d", &N);
 
        priority_queue<Cache, vector<Cache>, Compare> maxHeap;
        for (int j = 0; j < N; j++) {
            scanf("%d", &board[j]);
            vector<Cache> temp;
            bool found = false;
            while (maxHeap.size() > 0) {
                Cache item = maxHeap.top();
                if (item.number < board[j]) {
                    Cache *newItem = new Cache;
 
                    newItem->number = board[j];
                    newItem->length = item.length + 1;
 
                    maxHeap.push(*newItem);
                    found = true;
                    break;
                }
                temp.push_back(item);
                maxHeap.pop();
            }
 
            // 
            if (!found) {
                Cache *newItem = new Cache;
 
                newItem->number = board[j];
                newItem->length = 1;
 
                maxHeap.push(*newItem);
            }
 
            //
            for (int k = 0; k < temp.size(); k++) {
                maxHeap.push(temp.at(k));
            }
        }
 
        printf("%d\n", maxHeap.top().length);
    }
 
    return 0;
}
cs