본문 바로가기

알고리즘49

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.
2020 ICPC Sinchon Summer Algorithm Camp Contest Open 참여 #include using namespace std; int W0, I0, T, D, I, A; int newWeight, newBm; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> W0 >> I0 >> T >> D >> I >> A; // not considering bm delta newWeight = W0 + (I - (I0 + A)) * D; if (newWeight > 0) cout > T; for (int i = 0; i > input; giant.push(input); } if (giant.top() K; line.resize(M); for.. 2020. 9. 6.
Trie #include using namespace std; const int childMax = 26; const char baseChar = 'A'; struct Trie { Trie* child[childMax]; // 'A' ~ 'Z' bool isRet, isParent; Trie() { fill(child, child + childMax, nullptr); isRet = isParent = false; } ~Trie() { for (int i = 0; i < childMax; ++i) { if (child[i]) delete child[i]; } } void insert(const char* key) { if (*key == '\0') isRet = true; else { int next = *key.. 2020. 9. 4.
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.
Z 길이 $n$의 문자열 $S[0:n]$에 대하여 $Array Z[0:n]$를 $O(n)$에 구한다. $i$ $Z$ a n a n a b 0 6 a n a n a b 1 0 n a n a b 2 3 a n a b 3 0 n a b 4 1 a b 5 0 b $Z[i]$는 $S[0:]$와 $S[i:]$의 최대 공통 접두사의 길이이다. 코드는 다음과 같이 작성하였다. def getZ(s): l,r=0,0 ret=[0]*len(s) ret[0]=len(s) for i in range(1,len(s)): if i>r: l=r=i while r 2020. 8. 15.
Floyd-Warshall #include #include #define INF 1e9 #define NODES 101 using namespace std; int N, M; // 노드 간선 수 int dist[NODES][NODES]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin >> N >> M; for (int i = 1; i > v >> w; dist[u][v] = min(dist[u][v], w); } for (int k = 1; k 2020. 8. 15.