본문 바로가기

알고리즘/Codeforces19

Codeforces Round #683 (Div. 2, by Meet IT) AB import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) print(n) for i in range(n): print(i+1, end=" ") print() A - Add Candies 한 바구니를 선택한다는 조건을 무시하면, 사탕을 n번 넣었을 때 모든 바구니에 똑같이 (n * (n+1))/2 개의 사탕을 넣게 된다. 이때 각 바구니에 들어있는 사탕 수는 처음과 같이 등차 +1의 관계를 가진다. 따라서 1번 바구니부터 1, 2, 3... 순서로 빼주면 모든 바구니가 같은 수의 사탕을 가지게 된다. 결론은 1번부터 n번까지 순서대로 한 번 씩 선택하면 된다. #include using namespace std;.. 2020. 11. 16.
Codeforces Round #669 (Div. 2) ABC from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input())): l = int(input()) s = list(map(int, input().split())) r = [] for i in range(l//2): if s[i*2] == 0 and s[i*2+1] == 0: r.append(0); r.append(0); elif s[i*2] == 1 and s[i*2+1] == 1: r.append(1); r.append(1); else: r.append(0); print(len(r)) print(*r) A - Ahahahahahahahaha 입력의 길이가 반드시 2n이라는 점에 근거하여 두 자리씩.. 2020. 9. 9.
Codeforces Round #666 (Div. 2) AC #include using namespace std; int TEST; int n; string s; map chars; int cnt[26]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> TEST; while (TEST--) { cin >> n; for (int i = 0; i > s; for (char c : s) { cnt[int(c - 'a')] += 1; } } bool isGood = true; for (int i = 0; i < 26; ++i) { if (cnt[i] % n != 0) isGood = false; cnt[i] = 0; } cout n; for (int i = 1; i.. 2020. 8. 31.
Educational Codeforces Round 93 (Rated for Div. 2) AB from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input())): L=int(input()) s=list(map(int,input().split())) if s[0]+s[1]>s[-1]: print(-1) else: print(1,2,L) A - Bad Triangle 입력이 오름차순이므로 1, 2번과 마지막번만 비교하면 된다. from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input())): s=input().split("0") for i in range(len(s)): s[i]=len(.. 2020. 8. 15.
Codeforces Round #664 (Div. 2) AB #include #include #include #include #include using namespace std; int T; int r, g, b, w; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin >> T; while (T--) { cin >> r >> g >> b >> w; int r_, g_, b_, w_; r_ = r % 2; g_ = g % 2; b_ = b % 2; w_ = w % 2; if (r == 0 || g == 0 || b == 0) { if (r_ + g_ + b_ + w_ == 3 || r_ + g_ + b_ + w_ == 2) cout c; prnt(); visit[r][c] = true; to_tl.. 2020. 8. 13.
Codeforces Round #663 (Div. 2) ABC from sys import stdin def input(): return stdin.readline().rstrip() for i in range(int(input())): n=int(input()) for _ in range(1,n+1): print(_,end=" ") print() A - Suborrays 0분에 제출한 사람이 너무 많아서 단순히 n까지 출력하는 도박을 했고 AC를 받았다. from sys import stdin def input(): return stdin.readline().rstrip() T=int(input()) for i in range(T): res=0 r,c=map(int,input().split()) for j in range(r): line=input() if j==.. 2020. 8. 10.