├── .gitignore ├── .vscode ├── settings.json └── tasks.json ├── Competition ├── Fik Fair │ ├── 1.cpp │ ├── 10.cpp │ ├── 2.cpp │ ├── 3.cpp │ ├── 4.cpp │ ├── 5.cpp │ ├── 6.cpp │ ├── 7.cpp │ ├── 8.cpp │ ├── 9.cpp │ └── Grant Gabriel Tambunan.pdf ├── Gemastik │ ├── 2021 │ │ └── Penyisihan │ │ │ ├── Jawaban │ │ │ ├── .[J] Maximum Sum of Array.cpp.un~ │ │ │ ├── [A] Undian Berhadiah.cpp │ │ │ ├── [B] Laser Iron-Man.cpp │ │ │ ├── [C] Portal dan Monster.cpp │ │ │ ├── [D] Sihir Loki.cpp │ │ │ ├── [E] Bitcoin.cpp │ │ │ ├── [G] Jalan Jalan Virtual.cpp │ │ │ ├── [H] Soal Gemastik.cpp │ │ │ ├── [I] Plagiarisme.cpp │ │ │ ├── [J] Maximum Sum of Array.cpp │ │ │ └── [J] Maximum Sum of Array.cpp~ │ │ │ └── Soal │ │ │ ├── prob-[A] Undian Berhadiah.pdf │ │ │ ├── prob-[B] Laser Iron Man.pdf │ │ │ ├── prob-[C] Portal dan Monster.pdf │ │ │ ├── prob-[D] Sihir Loki.pdf │ │ │ ├── prob-[E] Bitcoin.pdf │ │ │ ├── prob-[F] Pencerminan Prefix Suffix.pdf │ │ │ ├── prob-[G] Jalan Jalan Virtual.pdf │ │ │ ├── prob-[H] Soal Gemastik.pdf │ │ │ ├── prob-[I] Plagiarisme.pdf │ │ │ └── prob-[J] Maximum Sum of Array.pdf │ ├── 2022 │ │ └── Penyisihan │ │ │ ├── Jawaban │ │ │ ├── [A] Pecahan.cpp │ │ │ ├── [B] Pendakian Gunung.cpp │ │ │ ├── [C] Ubin.cpp │ │ │ ├── [D] Array K-Cantik.cpp │ │ │ ├── [E] Jangkauan Bom.cpp │ │ │ ├── [F] Permainan Batu.cpp │ │ │ ├── [G] Selisih Anagram Minimum.cpp │ │ │ ├── [H] Soal Query Digit.cpp │ │ │ └── [I] Mengurutkan Karakter.cpp │ │ │ └── Soal │ │ │ ├── [A] Pecahan.pdf │ │ │ ├── [B] Pendakian Gunung.pdf │ │ │ ├── [C] Ubin.pdf │ │ │ ├── [D] Array K-Cantik.pdf │ │ │ ├── [E] Jangkauan Bom.pdf │ │ │ ├── [F] Permainan Batu.pdf │ │ │ ├── [G] Selisih Anagram Minimum.pdf │ │ │ ├── [H] Soal Query Digit.pdf │ │ │ └── [I] Mengurutkan Karakter.pdf │ └── 2023 │ │ ├── Penyisihan │ │ ├── Jawaban │ │ │ ├── A.cpp │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ ├── G.cpp │ │ │ └── H.cpp │ │ ├── Soal │ │ │ ├── [A] Es Kopi Boba.pdf │ │ │ ├── [B] Flappy Angry Birds.pdf │ │ │ ├── [C] MinES.pdf │ │ │ ├── [D] Kolam Ikan.pdf │ │ │ ├── [E] Ringkasan Bilangan.pdf │ │ │ ├── [F] Produk Wirausaha Provinsi.pdf │ │ │ ├── [G] Array Keren.pdf │ │ │ └── [H] Menghitung Lembah.pdf │ │ └── Submission │ │ │ ├── C.cpp │ │ │ └── E.cpp │ │ └── Pra-Penyisihan │ │ └── Jawaban │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp ├── Google Farewell Round │ └── Round A │ │ ├── 1.cpp │ │ ├── 2.cpp │ │ ├── 3.py │ │ ├── 4.py │ │ └── 5.py ├── HIMATIF CP │ └── 2022 │ │ ├── Jawaban │ │ ├── 1.c │ │ ├── 2.c │ │ ├── 3.c │ │ ├── 4.c │ │ └── 5.c │ │ └── Soal │ │ └── SOAL CP 2022.pdf ├── ICPC │ └── 2022 │ │ └── Final │ │ └── Problem │ │ ├── A - Storing Eggs.pdf │ │ ├── B - Magical Barrier.pdf │ │ ├── C - Nightmare Brother.pdf │ │ ├── D - City Hall.pdf │ │ ├── E - Substring Sort.pdf │ │ ├── F - Doubled GCD.pdf │ │ ├── G - The Only Mode.pdf │ │ ├── H - Grid Game.pdf │ │ ├── I - Contingency Plan.pdf │ │ ├── J - Sharing Bread.pdf │ │ ├── K - Short Function.pdf │ │ ├── L - Increase the Toll Fees.pdf │ │ └── M - Game Show.pdf ├── Meta Hacker Cup │ └── Practice Round │ │ ├── A1.cpp │ │ ├── A2.cpp │ │ ├── B.cpp │ │ ├── C-temp.cpp │ │ ├── C.cpp │ │ └── output.txt └── Pekan-IT UNSIKA │ ├── 1.cpp │ ├── 10.cpp │ ├── 2.cpp │ ├── 3.cpp │ ├── 4.cpp │ ├── 5.cpp │ ├── 6.cpp │ ├── 7.cpp │ ├── 8.cpp │ └── 9.cpp ├── Learning Material ├── Competitive Programming Handbook.pdf └── Pemrograman Kompetitif Dasar TOKI.pdf ├── Learning Progress ├── CSES │ ├── missing_number.cpp │ └── weird_algorithm.cpp └── TLX Toki │ ├── Gemastik 2023 │ └── A.cpp │ ├── Pemrograman Dasar │ ├── Submission │ │ ├── 1 │ │ │ └── 1A.cpp │ │ ├── 3 │ │ │ ├── 3B.cpp │ │ │ ├── 3C.cpp │ │ │ ├── 3D.cpp │ │ │ ├── 3E.cpp │ │ │ └── 3F.cpp │ │ ├── 5 │ │ │ ├── 5B.cpp │ │ │ ├── 5C.cpp │ │ │ ├── 5D.cpp │ │ │ ├── 5E.cpp │ │ │ ├── 5F.cpp │ │ │ └── 5G.cpp │ │ ├── 6 │ │ │ ├── 6B.cpp │ │ │ ├── 6C.cpp │ │ │ ├── 6D.cpp │ │ │ ├── 6E.cpp │ │ │ ├── 6F.cpp │ │ │ ├── 6G.cpp │ │ │ └── 6H.cpp │ │ ├── 7 │ │ │ ├── 7A.cpp │ │ │ ├── 7B.cpp │ │ │ └── 7C.cpp │ │ ├── 8 │ │ │ ├── 8B.cpp │ │ │ └── 8C.cpp │ │ ├── 9 │ │ │ ├── 9B.cpp │ │ │ ├── 9C.cpp │ │ │ ├── 9D.cpp │ │ │ └── 9E.cpp │ │ ├── 10 │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ └── F.cpp │ │ ├── 11 │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ └── F.cpp │ │ ├── 12 │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ └── E.cpp │ │ └── 13 │ │ │ ├── B.cpp │ │ │ ├── C.cpp │ │ │ ├── D.cpp │ │ │ ├── E.cpp │ │ │ ├── F.cpp │ │ │ └── G.cpp │ └── Testing │ │ ├── 10_PassByReference.cpp │ │ ├── 11_Cstring.cpp │ │ ├── 11_Erase_and_substr.cpp │ │ ├── 11_Insert.cpp │ │ ├── 11_Memset.cpp │ │ ├── 11_OperasiChar.cpp │ │ ├── 11_String.cpp │ │ ├── 12_Rekursi.cpp │ │ ├── 13_FibonacciRecursive.cpp │ │ ├── 13_PermutasiPass.cpp │ │ ├── 2_Struct.cpp │ │ ├── 3_Printf.cpp │ │ ├── 3_Scanf.cpp │ │ ├── 3_String.cpp │ │ ├── 3_XOR.cpp │ │ ├── 6_While.cpp │ │ ├── 7_Break.cpp │ │ ├── 7_Continue.cpp │ │ ├── 7_Nested_Loop.cpp │ │ ├── 7_Prime.cpp │ │ ├── 9_ArrayStruct.cpp │ │ ├── 9_Cokelat_Bebek.cpp │ │ └── 9_Ujian_Harian.cpp │ └── Pemrograman Kompetitif Dasar │ ├── 1. Perkenalan Pemrograman Kompetitif │ ├── Submission │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ └── D.cpp │ └── Testing │ │ └── lampu_dan_tombol.cpp │ ├── 2. Matematika Diskret Dasar │ └── Submission │ │ ├── A.cpp │ │ ├── B.cpp │ │ └── C.cpp │ ├── 3. Pencarian dan Pengurutan │ ├── Submission │ │ ├── A.cpp │ │ ├── B.cpp │ │ ├── C.cpp │ │ ├── D.cpp │ │ ├── E.cpp │ │ ├── F.cpp │ │ ├── G.cpp │ │ ├── H.cpp │ │ └── I.cpp │ └── Testing │ │ ├── binary_search.cpp │ │ ├── counting_sort.cpp │ │ ├── insertion_sort.cpp │ │ └── selection_sort.cpp │ └── 4. Brute Force │ ├── Submission │ ├── A.cpp │ └── B.cpp │ └── Testing │ └── subset_sum.cpp ├── README.md └── Template & Library ├── SimplifiedTemplateCP.cpp ├── TemplateCP.cpp └── TemplateCP.py /.gitignore: -------------------------------------------------------------------------------- 1 | *testing.cpp 2 | *testing.py 3 | *.exe 4 | *input.txt -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "any": "cpp", 4 | "array": "cpp", 5 | "atomic": "cpp", 6 | "barrier": "cpp", 7 | "bit": "cpp", 8 | "*.tcc": "cpp", 9 | "bitset": "cpp", 10 | "cctype": "cpp", 11 | "cfenv": "cpp", 12 | "charconv": "cpp", 13 | "chrono": "cpp", 14 | "cinttypes": "cpp", 15 | "clocale": "cpp", 16 | "cmath": "cpp", 17 | "codecvt": "cpp", 18 | "compare": "cpp", 19 | "complex": "cpp", 20 | "concepts": "cpp", 21 | "condition_variable": "cpp", 22 | "coroutine": "cpp", 23 | "csetjmp": "cpp", 24 | "csignal": "cpp", 25 | "cstdarg": "cpp", 26 | "cstddef": "cpp", 27 | "cstdint": "cpp", 28 | "cstdio": "cpp", 29 | "cstdlib": "cpp", 30 | "cstring": "cpp", 31 | "ctime": "cpp", 32 | "cuchar": "cpp", 33 | "cwchar": "cpp", 34 | "cwctype": "cpp", 35 | "deque": "cpp", 36 | "forward_list": "cpp", 37 | "list": "cpp", 38 | "map": "cpp", 39 | "set": "cpp", 40 | "string": "cpp", 41 | "unordered_map": "cpp", 42 | "unordered_set": "cpp", 43 | "vector": "cpp", 44 | "exception": "cpp", 45 | "expected": "cpp", 46 | "algorithm": "cpp", 47 | "functional": "cpp", 48 | "iterator": "cpp", 49 | "memory": "cpp", 50 | "memory_resource": "cpp", 51 | "numeric": "cpp", 52 | "optional": "cpp", 53 | "random": "cpp", 54 | "ratio": "cpp", 55 | "regex": "cpp", 56 | "source_location": "cpp", 57 | "string_view": "cpp", 58 | "system_error": "cpp", 59 | "tuple": "cpp", 60 | "type_traits": "cpp", 61 | "utility": "cpp", 62 | "fstream": "cpp", 63 | "future": "cpp", 64 | "initializer_list": "cpp", 65 | "iomanip": "cpp", 66 | "iosfwd": "cpp", 67 | "iostream": "cpp", 68 | "istream": "cpp", 69 | "latch": "cpp", 70 | "limits": "cpp", 71 | "mutex": "cpp", 72 | "new": "cpp", 73 | "numbers": "cpp", 74 | "ostream": "cpp", 75 | "ranges": "cpp", 76 | "scoped_allocator": "cpp", 77 | "semaphore": "cpp", 78 | "shared_mutex": "cpp", 79 | "span": "cpp", 80 | "spanstream": "cpp", 81 | "sstream": "cpp", 82 | "stacktrace": "cpp", 83 | "stdexcept": "cpp", 84 | "stop_token": "cpp", 85 | "streambuf": "cpp", 86 | "syncstream": "cpp", 87 | "thread": "cpp", 88 | "typeindex": "cpp", 89 | "typeinfo": "cpp", 90 | "valarray": "cpp", 91 | "variant": "cpp" 92 | }, 93 | "tasks": [ 94 | { 95 | "label": "crun", 96 | "type": "shell", 97 | "command": "powershell", 98 | "args": [ 99 | "-ExecutionPolicy", 100 | "Bypass", 101 | "-NoProfile", 102 | "-Command", 103 | "g++ -o test $fileName && ./test.exe" 104 | ], 105 | "problemMatcher": [] 106 | } 107 | ], 108 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: gcc.exe build active file", 6 | "command": "C:\\MinGW\\bin\\gcc.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /Competition/Fik Fair/1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | string ltrim(const string &); 6 | string rtrim(const string &); 7 | 8 | 9 | 10 | /* 11 | * Complete the 'input' function below. 12 | * 13 | * The function is expected to return a STRING. 14 | * The function accepts following parameters: 15 | * 1. STRING_ARRAY firstList 16 | * 2. STRING_ARRAY secondList 17 | * 3. STRING needle 18 | */ 19 | int main() 20 | { 21 | int x; cin >> x; 22 | string arr1[x]; 23 | for(int i = 0; i < x; i++) { 24 | cin >> arr1[i]; 25 | } 26 | 27 | int y; cin >> y; 28 | string arr2[y]; 29 | for(int i = 0; i < y; i++) { 30 | cin >> arr2[i]; 31 | } 32 | 33 | string temp; cin >> temp; 34 | bool tdkada = true; 35 | 36 | for(int i = 0; i < x; i++) { 37 | if(arr1[i] == temp) { 38 | cout << "satu "; tdkada = false; break; 39 | } 40 | } 41 | 42 | if(tdkada) { 43 | cout << "tidak_ada "; 44 | } 45 | 46 | tdkada = true; 47 | 48 | for(int i = 0; i < y; i++) { 49 | if(arr2[i] == temp) { 50 | cout << "dua"; tdkada = false; break; 51 | } 52 | } 53 | 54 | if(tdkada) { 55 | cout << "tidak_ada"; 56 | } 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Competition/Fik Fair/10.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/10.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/2.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/3.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/4.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/5.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/5.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/6.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/6.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/7.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/7.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/8.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/8.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/9.cpp -------------------------------------------------------------------------------- /Competition/Fik Fair/Grant Gabriel Tambunan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Fik Fair/Grant Gabriel Tambunan.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/.[J] Maximum Sum of Array.cpp.un~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Jawaban/.[J] Maximum Sum of Array.cpp.un~ -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[A] Undian Berhadiah.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define pii pair 6 | #define pll pair 7 | #define vi vector 8 | #define vll vector 9 | #define mii map 10 | #define si set 11 | #define sc set 12 | 13 | #define fors(i,s,e) for(long long int i=s;i=s;i--) 17 | #define pb push_back 18 | #define eb emplace_back 19 | #define sw swap 20 | 21 | template 22 | void print_v(vector &v) { 23 | cout << "{"; 24 | for (auto x : v) 25 | cout << x << ","; 26 | cout << "\b}"; 27 | } 28 | 29 | #define MOD 1000000007 30 | #define PI 3.1415926535897932384626433832795 31 | #define read(type) readInt() 32 | ll min(ll a,int b) { if (ab) return a; return b; } 35 | ll max(int a,ll b) { if (a>b) return a; return b; } 36 | ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } 37 | ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } 38 | 39 | string to_upper(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a;} 40 | string to_lower(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a;} 41 | 42 | bool prime(ll a) {if (a==1) return 0;for (int i=2;i<=round(sqrt(a));++i)if (a%i==0) return 0; return 1; } 43 | 44 | void yes() {cout<<"YES\n";} 45 | void no() {cout<<"NO\n";} 46 | void cs(int n) {cout<<"Case #"<> N >> Y; 60 | 61 | int X[N]; 62 | 63 | foro(i, N) { 64 | cin >> X[i]; 65 | min = abs(Y - X[i]); 66 | 67 | if(temp > min) { 68 | temp = min; 69 | nums = X[i]; 70 | } 71 | else if(temp == min) dub = true; 72 | } 73 | 74 | if(dub) { 75 | cout << Y - temp << '\n' << Y + temp; 76 | 77 | return 0; 78 | } 79 | 80 | cout << nums; 81 | 82 | return 0; 83 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[B] Laser Iron-Man.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | struct Point { 8 | int x; 9 | int y; 10 | }; 11 | 12 | struct Segment { 13 | Point p1; 14 | Point p2; 15 | }; 16 | 17 | int cross_product(Point a, Point b, Point c) { 18 | int x1 = a.x - b.x; 19 | int y1 = a.y - b.y; 20 | int x2 = c.x - b.x; 21 | int y2 = c.y - b.y; 22 | return x1*y2 - x2*y1; 23 | } 24 | 25 | bool intersect(Segment s1, Segment s2) { 26 | int c1 = cross_product(s1.p1, s1.p2, s2.p1); 27 | int c2 = cross_product(s1.p1, s1.p2, s2.p2); 28 | int c3 = cross_product(s2.p1, s2.p2, s1.p1); 29 | int c4 = cross_product(s2.p1, s2.p2, s1.p2); 30 | if ((c1 > 0 && c2 > 0) || (c1 < 0 && c2 < 0) || (c3 > 0 && c4 > 0) || (c3 < 0 && c4 < 0)) { 31 | return false; // no intersection 32 | } 33 | return true; // intersection 34 | } 35 | bool inside_polygon(Point p, vector polygon) { 36 | int count = 0; 37 | int n = polygon.size(); 38 | for (int i = 0; i < n; i++) { 39 | Segment s = {polygon[i], polygon[(i+1)%n]}; 40 | if (intersect(s, {p, {10000, p.y}})) { 41 | count++; 42 | } 43 | } 44 | return (count%2 == 1); 45 | } 46 | 47 | int main() { 48 | int x_iron, y_iron, N, K; 49 | cin >> x_iron >> y_iron >> N; 50 | vector robots(N); 51 | for (int i = 0; i < N; i++) { 52 | cin >> robots[i].x >> robots[i].y; 53 | } 54 | cin >> K; 55 | vector segments(K); 56 | for (int i = 0; i < K; i++) { 57 | cin >> segments[i].p1.x >> segments[i].p1.y >> segments[i].p2.x >> segments[i].p2.y; 58 | } 59 | int count = 0; 60 | for (int i = 0; i < N; i++) { 61 | Point robot = robots[i]; 62 | Segment laser = { {x_iron, y_iron}, robot }; 63 | bool hit = true; 64 | for (int j = 0; j < K; j++) { 65 | if (intersect(laser, segments[j])) { 66 | hit = false; 67 | break; 68 | } 69 | } 70 | if (hit) { 71 | count++; 72 | } 73 | } 74 | cout << count << endl; 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[C] Portal dan Monster.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Monster { 5 | int banyak; 6 | int 7 | }; 8 | 9 | int main() { 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | 13 | int N, K; 14 | cin >> N >> K; 15 | 16 | int monster[N], nodesarang[K][K]; 17 | 18 | for(int i = 0; i < N; i++) 19 | cin >> monster[i]; 20 | 21 | for(int i = 0; i < K; i++) { 22 | cin >> nodesarang[i][0]; 23 | cin >> nodesarang[0][i]; 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[D] Sihir Loki.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | ios_base::sync_with_stdio(false); 6 | cin.tie(NULL); 7 | 8 | int N, K, L; 9 | cin >> N; 10 | 11 | string benda[N]; 12 | for(int i = 0; i < N; i++) 13 | cin >> benda[i]; 14 | 15 | cin >> K >> L; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[E] Bitcoin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int N, untung = 0, tahan; 7 | bool beli = false; 8 | cin >> N; 9 | 10 | int prediksi[N]; 11 | for(int i = 0; i < N; i++) { 12 | cin >> prediksi[i]; 13 | } 14 | 15 | for(int i = 0; i < N - 1; i++) { 16 | if(prediksi[i] > prediksi[i + 1] && prediksi[i + 1] < prediksi[i + 2] && beli == false) { 17 | tahan = prediksi[i + 1]; 18 | beli = true; 19 | } else if(prediksi[i] < prediksi[i + 1] && prediksi[i + 1] > prediksi[i + 2] && beli == true) { 20 | untung += prediksi[i + 1] - tahan; 21 | beli = false; 22 | } 23 | } 24 | 25 | cout << untung; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[G] Jalan Jalan Virtual.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void runCases(int M) { 5 | if(M == 0) { cout << "0 0"; return;} 6 | 7 | int timur = 0, utara = 0, barat = 0, selatan = 0, checkPoint = M; 8 | for(int i = 1; i <= checkPoint; i++) { 9 | if(M - i <= 0) { 10 | if(i % 4 == 1) timur += M; 11 | else if(i % 4 == 2) utara += M; 12 | else if(i % 4 == 3) barat += M; 13 | else if(i % 4 == 0) selatan += M; 14 | 15 | break; 16 | } 17 | 18 | if(i % 4 == 1) { 19 | timur += i; 20 | M -= i; 21 | } else if(i % 4 == 2) { 22 | utara += i; 23 | M -= i; 24 | } else if(i % 4 == 3) { 25 | barat += i; 26 | M -= i; 27 | } else if(i % 4 == 0) { 28 | selatan += i; 29 | M -= i; 30 | } 31 | } 32 | 33 | cout << timur - barat << " " << utara - selatan; 34 | } 35 | 36 | int main() { 37 | int N, M; 38 | cin >> N; 39 | 40 | for(int i = 1; i <= N; i++) { 41 | cin >> M; 42 | runCases(M); 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[H] Soal Gemastik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define MOD 1000000007; 3 | using namespace std; 4 | 5 | int factorial(int n) { 6 | if(n == 0) return 1; 7 | 8 | return n * factorial(n - 1); 9 | } 10 | 11 | int main() { 12 | int a, b, c, d, N; 13 | cin >> N >> a >> b >> c >> d; 14 | 15 | int hasil = factorial(a - 1) * factorial(b - a - 1) * factorial(c - b - 1) * factorial(N - d); 16 | 17 | cout << hasil % MOD; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[I] Plagiarisme.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 4 | 5 | int FormattedMax(int arr[], int n) { 6 | int max = arr[0]; 7 | for(int i = 0; i < n; i++) arr[i] > max ? max == arr[i] : max == max; 8 | 9 | return max; 10 | } 11 | 12 | int FormattedMin(int arr[], int n) { 13 | int min = arr[0]; 14 | for(int i = 0; i < n; i++) arr[i] < min ? min == arr[i] : min == min; 15 | 16 | return min; 17 | } 18 | 19 | int factorial(int n) { 20 | if(n == 1) return 1; 21 | 22 | return n * factorial(n - 1); 23 | } 24 | 25 | int main() { 26 | boost; 27 | 28 | int N, M; 29 | 30 | cin >> N >> M; 31 | int menit[N][M], nilai[N][M]; 32 | 33 | for(int i = 0; i < N; i++) 34 | for(int j = 0; j < M; j++) 35 | cin >> nilai[i][j]; 36 | 37 | for(int i = 0; i < N; i++) 38 | for(int j = 0; j < M; j++) 39 | cin >> menit[i][j]; 40 | 41 | int hasil = 0, maksSementara[4][N]; 42 | 43 | for(int i = 0; i < M; i++) { 44 | for(int j = 0; j < N; j++) { 45 | maksSementara[0][j] = nilai[j][i] + menit[j][i] + j; 46 | maksSementara[0][j] = nilai[j][i] - menit[j][i] - j; 47 | maksSementara[0][j] = nilai[j][i] + menit[j][i] + j; 48 | maksSementara[0][j] = nilai[j][i] - menit[j][i] + j; 49 | } 50 | 51 | for (int j = 0; j < 4; j++) { 52 | hasil = max(hasil, FormattedMax(maksSementara[j], N) - FormattedMin(maksSementara[j], N)); 53 | } 54 | } 55 | 56 | cout << hasil; 57 | 58 | return 0; 59 | } 60 | 61 | // (abs(nilai[i][j + k] - nilai[i][j]) + abs(j - i)) > maks ? maks == (abs(nilai[i][j + k] - nilai[i][j]) + abs(j - i)) : maks == maks; 62 | /* 63 | 1 2 3 4 64 | 2 4 6 8 65 | 3 6 9 12 66 | 67 | */ 68 | 69 | -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[J] Maximum Sum of Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 3 | using namespace std; 4 | 5 | int main() { 6 | boost; 7 | 8 | 9 | int N, M, SUM; 10 | cin >> N >> M; 11 | vector nums(N); 12 | for(auto &num : nums) { 13 | cin >> num; 14 | } 15 | 16 | for(int num : nums) { 17 | 18 | 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Jawaban/[J] Maximum Sum of Array.cpp~: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 4 | using namespace std; 5 | 6 | int main() { 7 | boost; 8 | 9 | int N, M, maksimum = 0, jumlah = 0; 10 | cin >> N >> M; 11 | 12 | int array[N]; 13 | for(int i = 0; i < N; i++) 14 | cin >> array[i]; 15 | 16 | for(int i = 0; i < N; i++) { 17 | if(i >= M) { 18 | maksimum = max(maksimum, array[i - M]); 19 | // cout << "Maksimum " << i << " : " << maksimum << endl; 20 | array[i] += maksimum; 21 | // cout << "Array i setelah dijumlah dengan maksimum i " << array[i] << endl; 22 | } 23 | 24 | jumlah = max(array[i], jumlah); 25 | // cout << "Jumlah : " << jumlah << "\n" << endl; 26 | } 27 | 28 | cout << jumlah; 29 | 30 | return 0; 31 | } 32 | 33 | // 10 2 34 | // -1 2 5 7 -1 2 3 -2 4 8 -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[A] Undian Berhadiah.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[A] Undian Berhadiah.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[B] Laser Iron Man.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[B] Laser Iron Man.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[C] Portal dan Monster.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[C] Portal dan Monster.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[D] Sihir Loki.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[D] Sihir Loki.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[E] Bitcoin.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[E] Bitcoin.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[F] Pencerminan Prefix Suffix.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[F] Pencerminan Prefix Suffix.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[G] Jalan Jalan Virtual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[G] Jalan Jalan Virtual.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[H] Soal Gemastik.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[H] Soal Gemastik.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[I] Plagiarisme.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[I] Plagiarisme.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2021/Penyisihan/Soal/prob-[J] Maximum Sum of Array.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2021/Penyisihan/Soal/prob-[J] Maximum Sum of Array.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[A] Pecahan.cpp: -------------------------------------------------------------------------------- 1 | // General solution : Ya pembagian doang anjir tinggal bandingkan. 2 | 3 | #include 4 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 5 | #define lb "lebih besar" 6 | #define lk "lebih kecil" 7 | #define sm "sama" 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | long long A, B, C, D; 13 | cin >> A >> B >> C >> D; 14 | if(A * D == B * C) cout << sm; 15 | else if(A * D < B * C) cout << lk; 16 | else cout << lb; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[B] Pendakian Gunung.cpp: -------------------------------------------------------------------------------- 1 | // General solution : 2 | 3 | #include 4 | #define ll long long 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 6 | using namespace std; 7 | 8 | int main() { 9 | boost; 10 | 11 | ll N, M; 12 | cin >> N, M; 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[C] Ubin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | unsigned long long int faktorial(int n){ 6 | if(n == 1 || n == 0){ 7 | return 1; 8 | } 9 | 10 | return n * faktorial(n - 1); 11 | } 12 | 13 | unsigned long long int kombinasi(int a, int b){ 14 | return faktorial(a) / (faktorial(b) * faktorial(a - b)); 15 | } 16 | 17 | int main(){ 18 | int N, pivot = 0; 19 | unsigned long long int jumlah = 0; 20 | 21 | cin >> N; 22 | 23 | if(N % 2 == 0){ 24 | for(int i = N; i >= N / 2; i--){ 25 | jumlah += kombinasi(i, pivot); 26 | pivot++; 27 | // cout << "Jumlah : " << jumlah << "\n"; 28 | } 29 | }else{ 30 | for(int i = N; i >= N / 2 + 1; i--){ 31 | jumlah += kombinasi(i, pivot); 32 | pivot++; 33 | // cout << "Jumlah : " << jumlah << "\n"; 34 | } 35 | } 36 | 37 | cout << (jumlah * jumlah) % 1000000007 << endl; 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[D] Array K-Cantik.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define all(a) a.begin(), a.end() 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int main() { 29 | boost; 30 | 31 | int N; cin >> N; 32 | vector arr(N); 33 | unordered_map maps; 34 | 35 | for(int x : arr) { 36 | cin >> x; 37 | maps[x]++; 38 | } 39 | 40 | for(int i = 1; i <= N; i++) { 41 | 42 | } 43 | 44 | 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[E] Jangkauan Bom.cpp: -------------------------------------------------------------------------------- 1 | // General solution : Get distance from the circle centre point, compare it to the radius and count the impact. 2 | 3 | #include 4 | #define ll long long 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 6 | using namespace std; 7 | 8 | float line_distance(int x1, int y1, int x2, int y2) { 9 | int formula = (abs(x2 - x1) * abs(x2 - x1)) + (abs(y2 - y1) * abs(y2 - y1)); 10 | return sqrt(formula); 11 | } 12 | 13 | void run_cases(int koorX[], int koorY[], int bom, int X, int Y, int N) { 14 | int insider = 0; 15 | for(int i = 0; i < N; i++) { 16 | float temp = line_distance(X, Y, koorX[i], koorY[i]); 17 | 18 | if(temp <= bom) insider++; 19 | } 20 | 21 | cout << insider; 22 | } 23 | 24 | int main() { 25 | boost; 26 | int X, Y, N, Q; 27 | cin >> X >> Y >> N; 28 | 29 | int koorX[N], koorY[N]; 30 | for(int i = 0; i < N; i++) cin >> koorX[i] >> koorY[i]; 31 | 32 | cin >> Q; 33 | 34 | int bom; 35 | for(int i = 0; i < Q; i++) { 36 | cin >> bom; 37 | run_cases(koorX, koorY, bom, X, Y, N); 38 | } 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[F] Permainan Batu.cpp: -------------------------------------------------------------------------------- 1 | // General solution : 2 | 3 | #include 4 | #define ull unsigned long long 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 6 | using namespace std; 7 | 8 | ull batuXOR(ull N) { 9 | if(N % 4 == 0) return N; 10 | if(N % 4 == 1) return 1; 11 | if(N % 4 == 2) return N + 1; 12 | if(N % 4 == 3) return 0; 13 | } 14 | 15 | int main() { 16 | boost; 17 | 18 | ull N, K, M; 19 | cin >> N >> K >> M; 20 | 21 | if(M % 2 == 0) { 22 | cout << "Kedua"; 23 | return 0; 24 | } else { 25 | if(!(batuXOR(N - 1)^batuXOR(N - K - 1))) { 26 | cout << "Kedua"; 27 | return 0; 28 | } 29 | 30 | cout << "Pertama"; 31 | return 0; 32 | } 33 | 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[G] Selisih Anagram Minimum.cpp: -------------------------------------------------------------------------------- 1 | // General solution : Use "next_permutation" and "prev_permutation" to check the minumum. *(!) 2 | 3 | // #include 4 | // #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 5 | // #define ll long long 6 | // using namespace std; 7 | 8 | // int main() { 9 | // boost; 10 | 11 | // ll N; 12 | // cin >> N; 13 | // string tempNext = to_string(N), tempPrev = to_string(N); 14 | 15 | // ll arrayNext, arrayPrev, minimum = 9999999; 16 | 17 | // (next_permutation(tempNext.begin(), tempNext.end())); 18 | // (prev_permutation(tempPrev.begin(), tempPrev.end())); 19 | 20 | // arrayNext = stoll(tempNext); 21 | // arrayPrev = stoll(tempPrev); 22 | 23 | // minimum = min(minimum, abs(arrayNext - N)); 24 | // minimum = min(minimum, abs(arrayPrev - N)); 25 | 26 | // cout << minimum; 27 | 28 | // return 0; 29 | // } 30 | 31 | // 313 32 | // 331 33 | // 133 34 | 35 | 36 | #include 37 | #define ll long long 38 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 39 | using namespace std; 40 | 41 | ll run_cases(string x) { 42 | ll minimum = 9999999999; 43 | string tempString = x; 44 | ll num = stoll(x); 45 | 46 | sort(tempString.begin(), tempString.end()); 47 | 48 | do { 49 | ll pivot = stoll(tempString); 50 | // cout << pivot << endl; 51 | ll difference = abs(num - pivot); 52 | 53 | if(num != pivot) minimum = min(difference, minimum); 54 | } while(next_permutation(tempString.begin(), tempString.end())); 55 | 56 | return minimum; 57 | } 58 | 59 | 60 | int main() { 61 | boost; 62 | 63 | string N; 64 | cin >> N; 65 | 66 | cout << run_cases(N); 67 | 68 | return 0; 69 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[H] Soal Query Digit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 4 | using namespace std; 5 | 6 | string run_query1(const string& A, ll L, ll R, ll K) { 7 | string modifiedA = A; 8 | 9 | for(ll i = L - 1; i < R; i++) { 10 | int temp = modifiedA[i] - '0'; 11 | temp = temp + K; 12 | temp = temp % 10; 13 | modifiedA[i] = char(temp + 48); 14 | } 15 | 16 | return modifiedA; 17 | } 18 | 19 | void run_query2(string A, ll L, ll R) { 20 | string temp = A.substr(L - 1, (R - L) + 1); 21 | ll tempNum = stoll(temp); 22 | cout << tempNum % 998244353; 23 | } 24 | 25 | int main() { 26 | boost; 27 | 28 | ll N, Q, query, L, R, K; 29 | string A, B; 30 | cin >> N >> Q; 31 | cin >> A; 32 | 33 | for(int i = 0; i < Q; i++) { 34 | cin >> query; 35 | if(query == 2) { 36 | cin >> L >> R; 37 | run_query2(A, L, R); 38 | } else if(query == 1) { 39 | cin >> L >> R >> K; 40 | B = run_query1(A, L, R, K); 41 | A = B; 42 | cout << A << endl; 43 | } 44 | } 45 | 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Jawaban/[I] Mengurutkan Karakter.cpp: -------------------------------------------------------------------------------- 1 | // General solution : Pindahkan pivot ke titik tidak pertukaran selanjutnya, sambil menambah nilai dari operasi. 2 | 3 | #include 4 | #define ll long long 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 6 | using namespace std; 7 | 8 | int main() { 9 | boost; 10 | ll N, pivot = 0; 11 | string A, B; 12 | cin >> N; 13 | cin >> A >> B; 14 | 15 | for(int i = 0; i < N; i++) { 16 | if(A[i] > B[i]) { 17 | pivot++; 18 | while(A[i] >= B[i]) i++; 19 | } 20 | } 21 | 22 | cout << pivot; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[A] Pecahan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[A] Pecahan.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[B] Pendakian Gunung.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[B] Pendakian Gunung.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[C] Ubin.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[C] Ubin.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[D] Array K-Cantik.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[D] Array K-Cantik.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[E] Jangkauan Bom.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[E] Jangkauan Bom.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[F] Permainan Batu.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[F] Permainan Batu.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[G] Selisih Anagram Minimum.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[G] Selisih Anagram Minimum.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[H] Soal Query Digit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[H] Soal Query Digit.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2022/Penyisihan/Soal/[I] Mengurutkan Karakter.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2022/Penyisihan/Soal/[I] Mengurutkan Karakter.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define all(a) a.begin(), a.end() 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | vector temp; 28 | 29 | int findIndex(int e) { 30 | for(int i = 0; i < temp.size(); i++) 31 | if(temp[i] == e) 32 | return i + 1; 33 | 34 | return -1; 35 | } 36 | 37 | int main() { 38 | boost; 39 | 40 | int N; cin >> N; 41 | 42 | vector cup; int x; 43 | for(int i = 1; i <= N; i++) { 44 | cin >> x; 45 | cup.emplace_back(x); 46 | } 47 | 48 | temp = cup; 49 | sort(all(cup)); 50 | int maxE = *max_element(all(cup)); 51 | int minE = *min_element(all(cup)); 52 | 53 | if(minE == maxE) 54 | cout << "SESUAI"; 55 | else { 56 | int sum = 0; 57 | for(int x : cup) 58 | sum += x; 59 | 60 | int avg = (int)((sum - minE - maxE) / (N - 2)); 61 | int avgw = (int)((sum) / (N)); 62 | if(avg != avgw) 63 | cout << "TIDAK SESUAI"; 64 | else { 65 | cout << (int)((maxE - minE) / 2) << " " << findIndex(maxE) << " " << findIndex(minE); 66 | } 67 | } 68 | 69 | return 0; 70 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/B.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Jawaban/B.cpp -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/C.cpp: -------------------------------------------------------------------------------- 1 | // Solved By : Grant Gabriel Tambunan 2 | // Connect With Me : https://www.linkedin.com/in/grantgabrieltambunan/ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | using namespace std; 24 | 25 | #define ll long long 26 | #define ull unsigned long long 27 | #define all(a) a.begin(), a.end() 28 | #define debug(a) cout << a << endl 29 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 30 | 31 | int main() { 32 | boost; 33 | 34 | unordered_map mp1 = { 35 | {"AB", "AA"}, {"DC", "AB"}, {"CC", "AC"}, {"CB", "AD"}, 36 | {"CA", "BA"}, {"DA", "BB"}, {"CD", "BC"}, {"DD", "BD"}, 37 | {"BC", "CA"}, {"AA", "CB"}, {"BA", "CC"}, {"DB", "CD"}, 38 | {"BD", "DA"}, {"AD", "DB"}, {"BB", "DC"}, {"AC", "DD"} 39 | }; 40 | 41 | unordered_map mp2 = { 42 | {"CD", "AA"}, {"BB", "AB"}, {"AC", "AC"}, {"CC", "AD"}, 43 | {"CB", "BA"}, {"DB", "BB"}, {"AD", "BC"}, {"DD", "BD"}, 44 | {"DA", "CA"}, {"DC", "CB"}, {"BC", "CC"}, {"BD", "CD"}, 45 | {"AA", "DA"}, {"BA", "DB"}, {"CA", "DC"}, {"AB", "DD"} 46 | }; 47 | 48 | string x; cin >> x; 49 | 50 | string ans = ""; 51 | for(int i = 0; i < x.size(); i+=2) { 52 | string temp = x.substr(i, 2); 53 | temp = mp2[temp]; 54 | temp = mp1[temp]; 55 | 56 | ans += temp; 57 | } 58 | 59 | cout << ans; 60 | return 0; 61 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/D.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Jawaban/D.cpp -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int N; 8 | cin >> N; 9 | 10 | vector numbers(N); 11 | int temp; 12 | for (int i = 0; i < N; ++i) { 13 | cin >> temp; 14 | numbers.push_back(temp); 15 | } 16 | 17 | sort(numbers.begin(), numbers.end()); 18 | numbers.erase(unique(numbers.begin(), numbers.end()), numbers.end()); 19 | vector step; 20 | int j = 0; 21 | for(int i = 0; i < numbers.size(); i++) { 22 | bool flag = true; int temp; 23 | if(numbers[i] + 1 == numbers[i + 1] and flag) { 24 | flag = false; 25 | temp = numbers[i]; 26 | while(numbers[i] + 1 == numbers[i + 1]) { 27 | i++; 28 | } 29 | } else if(numbers[i] + 1 != numbers[i + 1]) { 30 | string tempStr = ""; 31 | tempStr += to_string(temp)+'-'+to_string(numbers[i]); 32 | step.push_back(tempStr); 33 | } 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/F.cpp: -------------------------------------------------------------------------------- 1 | // Solved By : Grant Gabriel Tambunan 2 | // Connect With Me : https://www.linkedin.com/in/grantgabrieltambunan/ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | using namespace std; 24 | 25 | #define ll long long 26 | #define ull unsigned long long 27 | #define all(a) a.begin(), a.end() 28 | #define debug(a) cout << a << endl 29 | #define boost \ 30 | ios_base::sync_with_stdio(false); \ 31 | cin.tie(NULL) 32 | 33 | void generateSubsetSums(const vector &nums, vector &subsetSums) 34 | { 35 | int n = nums.size(); 36 | int numOfSubsets = 1 << n; // 2^n subsets 37 | 38 | for (int i = 0; i < numOfSubsets; ++i) 39 | { 40 | int sum = 0; 41 | for (int j = 0; j < n; ++j) 42 | { 43 | if (i & (1 << j)) 44 | { 45 | sum += nums[j]; 46 | } 47 | } 48 | subsetSums.push_back(sum); 49 | } 50 | } 51 | 52 | int closestSum(const vector &nums, int target) 53 | { 54 | int n = nums.size(); 55 | int half = n / 2; 56 | 57 | // Generate subset sums for each half 58 | vector firstHalfSums, secondHalfSums; 59 | generateSubsetSums(vector(nums.begin(), nums.begin() + half), firstHalfSums); 60 | generateSubsetSums(vector(nums.begin() + half, nums.end()), secondHalfSums); 61 | 62 | // Sort the sums of the second half 63 | sort(secondHalfSums.begin(), secondHalfSums.end()); 64 | 65 | int closest = INT_MAX, closestSum = 0; 66 | 67 | // Iterate over all sums of the first half 68 | for (int sum1 : firstHalfSums) 69 | { 70 | // Find the closest sum in the second half using binary search 71 | auto it = lower_bound(secondHalfSums.begin(), secondHalfSums.end(), target - sum1); 72 | 73 | // Check the closest sums found in the second half 74 | if (it != secondHalfSums.end()) 75 | { 76 | int sum2 = *it; 77 | int currentSum = sum1 + sum2; 78 | // Update closestSum if the current sum is closer to target or has a lower sum with the same closeness 79 | if (abs(currentSum - target) < abs(closestSum - target) || 80 | (abs(currentSum - target) == abs(closestSum - target) && currentSum < closestSum)) 81 | { 82 | closest = abs(currentSum - target); 83 | closestSum = currentSum; 84 | } 85 | } 86 | if (it != secondHalfSums.begin()) 87 | { 88 | int sum2 = *(--it); 89 | int currentSum = sum1 + sum2; 90 | // Update closestSum if the current sum is closer to target or has a lower sum with the same closeness 91 | if (abs(currentSum - target) < abs(closestSum - target) || 92 | (abs(currentSum - target) == abs(closestSum - target) && currentSum < closestSum)) 93 | { 94 | closest = abs(currentSum - target); 95 | closestSum = currentSum; 96 | } 97 | } 98 | } 99 | 100 | return closestSum; 101 | } 102 | 103 | int main() 104 | { 105 | boost; 106 | 107 | int P, N, K; 108 | cin >> P >> N >> K; 109 | 110 | map> m1; 111 | string temp; 112 | cin.ignore(); 113 | for (int i = 0; i < P; i++) 114 | { 115 | getline(cin, temp); 116 | 117 | for (int j = 0; j < N; j++) 118 | { 119 | int htemp; 120 | cin >> htemp; 121 | m1[temp].emplace_back(htemp); 122 | } 123 | 124 | cin.ignore(); 125 | } 126 | 127 | map m; 128 | 129 | for (const auto &pair : m1) 130 | { 131 | int y = closestSum(pair.second, K); 132 | m[pair.first] = y; 133 | } 134 | 135 | int minE = INT_MAX; 136 | for (const auto &pair : m) 137 | { 138 | minE = min(minE, abs(pair.second - K)); 139 | } 140 | 141 | vector ans; 142 | for (const auto &pair : m) 143 | { 144 | if (abs(pair.second - K) == minE) 145 | ans.emplace_back(pair.first); 146 | } 147 | 148 | sort(ans.begin(), ans.end()); 149 | cout << ans[0]; 150 | 151 | return 0; 152 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/G.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Jawaban/G.cpp -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Jawaban/H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool isSquare(int n) { 9 | int sqrt_n = sqrt(n); 10 | return sqrt_n * sqrt_n == n; 11 | } 12 | 13 | int findSmallestK(int N, vector& A) { 14 | unordered_set squaresSet; 15 | for (int num : A) { 16 | if (isSquare(num)) { 17 | squaresSet.insert(num); 18 | } 19 | } 20 | 21 | if (squaresSet.size() < N) { 22 | return -1; 23 | } 24 | 25 | for (int K = N; K >= 2; K--) { 26 | bool containsNonSquare = false; 27 | for (int i = 0; i <= N - K; i++) { 28 | bool subsequenceKIsSquare = true; 29 | for (int j = i; j < i + K; j++) { 30 | if (squaresSet.find(A[j]) == squaresSet.end()) { 31 | subsequenceKIsSquare = false; 32 | break; 33 | } 34 | } 35 | if (subsequenceKIsSquare) { 36 | return K; 37 | } 38 | } 39 | } 40 | 41 | return N; 42 | } 43 | 44 | int main() { 45 | int N; 46 | cin >> N; 47 | 48 | vector A(N); 49 | for (int i = 0; i < N; i++) { 50 | cin >> A[i]; 51 | } 52 | 53 | int result = findSmallestK(N, A); 54 | cout << result << endl; 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[A] Es Kopi Boba.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[A] Es Kopi Boba.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[B] Flappy Angry Birds.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[B] Flappy Angry Birds.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[C] MinES.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[C] MinES.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[D] Kolam Ikan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[D] Kolam Ikan.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[E] Ringkasan Bilangan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[E] Ringkasan Bilangan.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[F] Produk Wirausaha Provinsi.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[F] Produk Wirausaha Provinsi.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[G] Array Keren.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[G] Array Keren.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Soal/[H] Menghitung Lembah.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Penyisihan/Soal/[H] Menghitung Lembah.pdf -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Submission/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define BOOST ios_base::sync_with_stdio(false); cin.tie(NULL); 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | BOOST 8 | int jumlahN, pivot = 0; 9 | string N, baru = ""; 10 | cin >> N; 11 | 12 | jumlahN = N.length(); 13 | 14 | for(int i = 0; i < (jumlahN / 2); i++){ 15 | if(N.substr(pivot, 2) == "AA"){ 16 | baru += "BB"; 17 | }else if(N.substr(pivot, 2) == "AB"){ 18 | baru += "BD"; 19 | }else if(N.substr(pivot, 2) == "AC"){ 20 | baru += "DD"; 21 | }else if(N.substr(pivot, 2) == "AD"){ 22 | baru += "CA"; 23 | }else if(N.substr(pivot, 2) == "BA"){ 24 | baru += "CD"; 25 | }else if(N.substr(pivot, 2) == "BB"){ 26 | baru += "AA"; 27 | }else if(N.substr(pivot, 2) == "BC"){ 28 | baru += "AC"; 29 | }else if(N.substr(pivot, 2) == "BD"){ 30 | baru += "BC"; 31 | }else if(N.substr(pivot, 2) == "CA"){ 32 | baru += "AB"; 33 | }else if(N.substr(pivot, 2) == "CB"){ 34 | baru += "CC"; 35 | }else if(N.substr(pivot, 2) == "CC"){ 36 | baru += "DB"; 37 | }else if(N.substr(pivot, 2) == "CD"){ 38 | baru += "CB"; 39 | }else if(N.substr(pivot, 2) == "DA"){ 40 | baru += "BA"; 41 | }else if(N.substr(pivot, 2) == "DB"){ 42 | baru += "DC"; 43 | }else if(N.substr(pivot, 2) == "DC"){ 44 | baru += "AD"; 45 | }else if(N.substr(pivot, 2) == "DD"){ 46 | baru += "DA"; 47 | } 48 | pivot += 2; 49 | } 50 | 51 | cout << baru << "\n"; 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Penyisihan/Submission/E.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Team : Aku Butuh Medkit 4 | * Captain : Grant Gabriel Tambunan 5 | * Member : Alwin Liufandy & Muhammad Luthfi 6 | * 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #define boost \ 14 | ios_base::sync_with_stdio(false); \ 15 | cin.tie(NULL); \ 16 | cout.tie(NULL); 17 | 18 | using namespace std; 19 | 20 | int main() 21 | { 22 | boost; 23 | long long N, a = 0, z = 0; 24 | long long awal = 0, akhir, simpanan; 25 | bool q = true; 26 | cin >> N; 27 | 28 | vector numbers(N); 29 | 30 | long long arr[N]; 31 | 32 | string hasil[N]; 33 | 34 | for (long long i = 0; i < N; i++) 35 | { 36 | cin >> numbers[i]; 37 | } 38 | 39 | sort(numbers.begin(), numbers.end()); 40 | 41 | for (long long i = 0; i < N; i++) 42 | { 43 | if (numbers[i] != numbers[i + 1]) 44 | { 45 | arr[a] = numbers[i]; 46 | a++; 47 | } 48 | } 49 | 50 | for (long long i = 0; i < a; i++) 51 | { 52 | if (arr[i + 1] - arr[i] == 1 && q == true) 53 | { 54 | awal = arr[i]; 55 | q = false; 56 | } 57 | else if (arr[i + 1] - arr[i] != 1 && q == false) 58 | { 59 | akhir = arr[i]; 60 | q = true; 61 | } 62 | else if (awal == 0) 63 | { 64 | simpanan = arr[i]; 65 | } 66 | 67 | if (q == true) 68 | { 69 | if (awal == 0) 70 | { 71 | hasil[z] = to_string(simpanan); 72 | } 73 | else 74 | { 75 | hasil[z] = to_string(awal) + "-" + to_string(akhir); 76 | awal = 0; 77 | } 78 | z++; 79 | } 80 | } 81 | 82 | for (long long i = 0; i < z - 1; i++) 83 | { 84 | cout << hasil[i] << ","; 85 | } 86 | cout << hasil[z - 1]; 87 | } 88 | -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Pra-Penyisihan/Jawaban/A.cpp: -------------------------------------------------------------------------------- 1 | // General solution : Ya pembagian doang anjir tinggal bandingkan. 2 | 3 | #include 4 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 5 | #define lb "lebih besar" 6 | #define lk "lebih kecil" 7 | #define sm "sama" 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | long long A, B, C, D; 13 | cin >> A >> B >> C >> D; 14 | if(A * D == B * C) cout << sm; 15 | else if(A * D < B * C) cout << lk; 16 | else cout << lb; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Pra-Penyisihan/Jawaban/B.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/Gemastik/2023/Pra-Penyisihan/Jawaban/B.cpp -------------------------------------------------------------------------------- /Competition/Gemastik/2023/Pra-Penyisihan/Jawaban/C.cpp: -------------------------------------------------------------------------------- 1 | // General solution : Pindahkan pivot ke titik tidak pertukaran selanjutnya, sambil menambah nilai dari operasi. 2 | 3 | #include 4 | #define ll long long 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); 6 | using namespace std; 7 | 8 | int main() { 9 | boost; 10 | ll N, pivot = 0; 11 | bool breakPoint = false; 12 | string A, B; 13 | cin >> N; 14 | cin >> A >> B; 15 | 16 | for(int i = 0; i < N; i++) { 17 | if(A[i] > B[i]) { 18 | if(breakPoint) { 19 | continue; 20 | } else { 21 | pivot++; 22 | breakPoint = true; 23 | } 24 | } else if(A[i] < B[i]) { 25 | breakPoint = false; 26 | } 27 | } 28 | 29 | cout << pivot; 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Competition/Google Farewell Round/Round A/1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define pii pair 6 | #define pll pair 7 | #define vi vector 8 | #define vll vector 9 | #define mii map 10 | #define si set 11 | #define sc set 12 | 13 | #define fors(i,s,e) for(long long int i=s;i=s;i--) 17 | #define pb push_back 18 | #define eb emplace_back 19 | #define sw swap 20 | 21 | template 22 | void print_v(vector &v) { 23 | cout << "{"; 24 | for (auto x : v) 25 | cout << x << ","; 26 | cout << "\b}"; 27 | } 28 | 29 | void bubbleSort(int arr[], int N) { 30 | for(int i = 0; i < N; i++) 31 | for(int j = 0; j < N; j++) 32 | if(arr[i] < arr[j]) 33 | sw(arr[i], arr[j]); 34 | } 35 | 36 | #define MOD 1000000007 37 | #define PI 3.1415926535897932384626433832795 38 | #define read(type) readInt() 39 | ll min(ll a,int b) { if (ab) return a; return b; } 42 | ll max(int a,ll b) { if (a>b) return a; return b; } 43 | ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } 44 | ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } 45 | 46 | string to_upper(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a;} 47 | string to_lower(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a;} 48 | 49 | bool prime(ll a) {if (a==1) return 0;for (int i=2;i<=round(sqrt(a));++i)if (a%i==0) return 0; return 1; } 50 | 51 | void yes() {cout<<"YES\n";} 52 | void no() {cout<<"NO\n";} 53 | void cs(int n) {cout<<"Case #"<> T; 68 | 69 | for (int i = 1; i <= T; i++) { 70 | unordered_map mapping; 71 | for (char c = 'A'; c <= 'Z'; c++) { 72 | int d; 73 | cin >> d; 74 | mapping[c] = d; 75 | } 76 | 77 | int N; 78 | cin >> N; 79 | 80 | unordered_map encoded; 81 | bool collision = false; 82 | for (int j = 0; j < N; j++) { 83 | string s; 84 | cin >> s; 85 | 86 | string encoding = ""; 87 | for (char c : s) { 88 | encoding += to_string(mapping[c]); 89 | } 90 | 91 | if (encoded.count(encoding)) { 92 | collision = true; 93 | } else { 94 | encoded[encoding] = j; 95 | } 96 | } 97 | 98 | cout << "Case #" << i << ": " << (collision ? "YES" : "NO") << endl; 99 | } 100 | 101 | return 0; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /Competition/Google Farewell Round/Round A/2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define pii pair 6 | #define pll pair 7 | #define vi vector 8 | #define vll vector 9 | #define mii map 10 | #define si set 11 | #define sc set 12 | 13 | #define fors(i,s,e) for(long long int i=s;i=s;i--) 17 | #define pb push_back 18 | #define eb emplace_back 19 | #define sw swap 20 | 21 | template 22 | void print_v(vector &v) { 23 | cout << "{"; 24 | for (auto x : v) 25 | cout << x << ","; 26 | cout << "\b}"; 27 | } 28 | 29 | #define MOD 1000000007 30 | #define PI 3.1415926535897932384626433832795 31 | #define read(type) readInt() 32 | ll min(ll a,int b) { if (ab) return a; return b; } 35 | ll max(int a,ll b) { if (a>b) return a; return b; } 36 | ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } 37 | ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } 38 | 39 | string to_upper(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a;} 40 | string to_lower(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a;} 41 | 42 | bool prime(ll a) {if (a==1) return 0;for (int i=2;i<=round(sqrt(a));++i)if (a%i==0) return 0; return 1; } 43 | 44 | void yes() {cout<<"YES\n";} 45 | void no() {cout<<"NO\n";} 46 | void cs(int n) {cout<<"Case #"<> T; 61 | 62 | for (i = 1; i <= T; i++) { 63 | int M, R, N; 64 | cin >> M >> R >> N; 65 | 66 | vector X(N); 67 | for (int j = 0; j < N; j++) { 68 | cin >> X[j]; 69 | } 70 | 71 | int ans = 0; 72 | i = 0; 73 | while (i < N) { 74 | int j = i; 75 | while (j < N && X[j] - X[i] <= R) { 76 | j++; 77 | } 78 | if (j == i) { 79 | // unable to cover the next streetlight 80 | break; 81 | } 82 | // place bulb at X[j-1] 83 | ans++; 84 | int p = j - 1; 85 | while (p < N && X[p] - X[j-1] <= R) { 86 | p++; 87 | } 88 | i = p - 1; 89 | } 90 | if (i < N && X[N-1] - X[i] > R) { 91 | // unable to cover the last segment 92 | cout << "Case #" << i << ": IMPOSSIBLE" << endl; 93 | } else { 94 | cout << "Case #" << i << ": " << ans << endl; 95 | } 96 | } 97 | 98 | return 0; 99 | } -------------------------------------------------------------------------------- /Competition/Google Farewell Round/Round A/3.py: -------------------------------------------------------------------------------- 1 | from bisect import bisect_left 2 | 3 | def num_lightbulbs(M, R, X): 4 | # First, we compute the intervals that each street light can cover 5 | intervals = [] 6 | for x in X: 7 | left = max(0, x-R) 8 | right = min(M, x+R) 9 | intervals.append((left, right)) 10 | 11 | # We sort the intervals by their left endpoint 12 | intervals.sort() 13 | 14 | # We keep track of the rightmost point that we have covered so far 15 | covered = 0 16 | # We keep track of the number of lightbulbs that we have installed 17 | num_bulbs = 0 18 | 19 | # We go through the intervals one by one, and if we encounter 20 | # an interval that is not covered by the previous lightbulbs, we 21 | # install a new one at its right endpoint. 22 | for left, right in intervals: 23 | if left > covered: 24 | return "IMPOSSIBLE" 25 | if right > covered: 26 | num_bulbs += 1 27 | covered = right 28 | return num_bulbs 29 | 30 | # Read the number of test cases 31 | T = int(input()) 32 | 33 | # Process each test case 34 | for t in range(1, T+1): 35 | M, R, N = map(int, input().split()) 36 | X = list(map(int, input().split())) 37 | result = num_lightbulbs(M, R, X) 38 | print(f"Case #{t}: {result}") -------------------------------------------------------------------------------- /Competition/Google Farewell Round/Round A/4.py: -------------------------------------------------------------------------------- 1 | def get_nth_char(n): 2 | # calculate the length of the string up to the N-th character 3 | i = 0 4 | while True: 5 | len_so_far = (2**i - 1) * 26 6 | if len_so_far >= n: 7 | break 8 | i += 1 9 | len_before = (2**(i-1) - 1) * 26 10 | len_after = length - len_before - 26 11 | length = len_before + len_after 12 | 13 | # find the N-th character using modular arithmetic 14 | index = (n-1) % length 15 | return chr(ord('A') + (index % 26)) 16 | 17 | # main program 18 | t = int(input()) 19 | for i in range(t): 20 | n = int(input()) 21 | c = get_nth_char(n) 22 | print("Case #{}: {}".format(i+1, c)) 23 | -------------------------------------------------------------------------------- /Competition/Google Farewell Round/Round A/5.py: -------------------------------------------------------------------------------- 1 | def min_changes(c): 2 | n = len(c) 3 | count = 0 4 | for i in range(n): 5 | if c[i] == c[(i+1)%n]: 6 | count += 1 7 | if c[i] == 'R': 8 | if c[(i+2)%n] == 'P': 9 | c[(i+1)%n] = 'S' 10 | else: 11 | c[(i+1)%n] = 'P' 12 | elif c[i] == 'P': 13 | if c[(i+2)%n] == 'R': 14 | c[(i+1)%n] = 'S' 15 | else: 16 | c[(i+1)%n] = 'R' 17 | else: 18 | if c[(i+2)%n] == 'R': 19 | c[(i+1)%n] = 'P' 20 | else: 21 | c[(i+1)%n] = 'R' 22 | return count 23 | 24 | t = int(input()) 25 | for i in range(t): 26 | c = input().strip() 27 | c = list(c) 28 | count = min_changes(c) 29 | print("Case #{}: {}".format(i+1, count)) -------------------------------------------------------------------------------- /Competition/HIMATIF CP/2022/Jawaban/1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int x ,i ,langkah = 0, lomp; 7 | printf("Berikan Lokasi Terakhir Kucing : "); 8 | scanf("%d", &x); 9 | 10 | if(x > 0) 11 | { 12 | lomp = 2*x; 13 | } 14 | else 15 | { 16 | lomp = 2 * abs(x) + 1; 17 | } 18 | 19 | for (i = 1; i < lomp; i++) 20 | { 21 | langkah = langkah + i; 22 | } 23 | 24 | printf("Kucing Telah Melangkah Sebanyak %d Langkah Jika Diumpamakan Di Diagram Cartesius",langkah); 25 | } -------------------------------------------------------------------------------- /Competition/HIMATIF CP/2022/Jawaban/2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int input, sementara; 6 | int aa = 0, bb = 0, cc = 0, dd = 0, ee = 0, ff = 0, gg = 0, hh = 0, ii = 0, jj = 0; 7 | 8 | printf("Masukkan Nilai Uang (Diantara 1 Sampai 10000), Maka Akan Saya Pecahkan! \n"); 9 | printf("Jumlah uang : "); 10 | scanf("%d", &input); 11 | 12 | sementara = input; 13 | 14 | if (input <= 10000 && input >= 1) 15 | { 16 | while (sementara >= 1000) 17 | { 18 | sementara = sementara - 1000; 19 | jj = jj + 1; 20 | } 21 | while (sementara >= 500) 22 | { 23 | sementara = sementara - 500; 24 | ii = ii + 1; 25 | } 26 | while (sementara >= 200) 27 | { 28 | sementara = sementara - 200; 29 | hh = hh + 1; 30 | } 31 | while (sementara >= 100) 32 | { 33 | sementara = sementara - 100; 34 | gg = gg + 1; 35 | } 36 | while (sementara >= 50) 37 | { 38 | sementara = sementara - 50; 39 | ff = ff + 1; 40 | } 41 | while (sementara >= 20) 42 | { 43 | sementara = sementara - 20; 44 | ee = ee + 1; 45 | } 46 | while (sementara >= 10) 47 | { 48 | sementara = sementara - 10; 49 | dd = dd + 1; 50 | } 51 | while (sementara >= 5) 52 | { 53 | sementara = sementara - 5; 54 | cc = cc + 1; 55 | } 56 | while (sementara >= 2) 57 | { 58 | sementara = sementara - 2; 59 | bb = bb + 1; 60 | } 61 | while (sementara >= 1) 62 | { 63 | sementara = sementara - 1; 64 | aa = aa + 1; 65 | } 66 | 67 | printf("Dibutuhkan Koin Sebanyak : \n"); 68 | 69 | if (jj > 0) 70 | printf("1000 = %dx \n", jj); 71 | if (ii > 0) 72 | printf("500 = %dx \n", ii); 73 | if (hh > 0) 74 | printf("200 = %dx \n", hh); 75 | if (gg > 0) 76 | printf("100 = %dx \n", gg); 77 | if (ff > 0) 78 | printf("50 = %dx \n", ff); 79 | if (ee > 0) 80 | printf("20 = %dx \n", ee); 81 | if (dd > 0) 82 | printf("10 = %dx \n", dd); 83 | if (cc > 0) 84 | printf("5 = %dx \n", cc); 85 | if (bb > 0) 86 | printf("2 = %dx \n", bb); 87 | if (aa > 0) 88 | printf("1 = %dx \n", aa); 89 | } 90 | else 91 | { 92 | printf("Nilai uang tidak sesuai kriteria!"); 93 | } 94 | 95 | return 0; 96 | } -------------------------------------------------------------------------------- /Competition/HIMATIF CP/2022/Jawaban/3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char kalimatawal[50]; 7 | char katabaru[50][50]; 8 | int i, j, batas; 9 | 10 | printf("Program Untuk Memisahkan Kata Pada Kalimat \n"); 11 | printf("\n \n"); 12 | 13 | printf("Masukkan Sebuah Kalimat : "); 14 | fgets(kalimatawal, sizeof kalimatawal, stdin); 15 | 16 | j = 0; 17 | batas = 0; 18 | 19 | for (i = 0; i <= (strlen(kalimatawal)); i++) 20 | { 21 | if (kalimatawal[i]==' ' || kalimatawal[i]=='\0') 22 | { 23 | katabaru[batas][j] = '\0'; 24 | batas++; 25 | j=0; 26 | } 27 | else 28 | { 29 | katabaru[batas][j]= kalimatawal[i]; 30 | j++; 31 | } 32 | } 33 | 34 | printf("\n\nKalimat Setelah Dipisah Adalah :\n"); 35 | 36 | for(i=0; i < batas; i++) 37 | printf("\"%s\"\n", katabaru[i]); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Competition/HIMATIF CP/2022/Jawaban/4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main () 6 | { 7 | char kata[50]; 8 | char sementara; 9 | 10 | printf("Masukkan Sebuah Kata, MAKA AKAN SAYA URUTKAN DIA SESUAI ABJAD !!!! \n"); 11 | printf("Kata : "); 12 | gets(kata); 13 | 14 | 15 | int i, j; 16 | int n = strlen(kata); 17 | 18 | printf("Kata Sebelum Diurutkan : %s \n", kata); 19 | 20 | for (i = 0; i < n - 1; i++) 21 | { 22 | for (j = i + 1; j < n; j++) 23 | { 24 | if (kata[i] > kata[j]) 25 | { 26 | sementara = kata[i]; 27 | kata[i] = kata[j]; 28 | kata[j] = sementara; 29 | } 30 | } 31 | } 32 | 33 | printf("Kata Sesudah diurutkan : %s \n", kata); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Competition/HIMATIF CP/2022/Jawaban/5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int array[22] = {67, 111, 109, 112, 101, 116, 105, 116, 105, 118, 101, 32, 80, 114, 111, 103, 114, 97, 109, 105, 110, 103}; 6 | 7 | printf("Program Untuk Translate Sebuah Kode, Dari Angka Ke ASCII! \n"); 8 | printf("Kode adalah : \n"); 9 | printf("67 111 109 112 101 116 105 116 105 118 101 32 80 114 111 103 114 97 109 105 110 103 \n"); 10 | printf("Kode Setelah Ditranslate : "); 11 | 12 | 13 | for(int i = 0; i < 22; i++) 14 | { 15 | printf("%c", array[i]); 16 | } 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Competition/HIMATIF CP/2022/Soal/SOAL CP 2022.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/HIMATIF CP/2022/Soal/SOAL CP 2022.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/A - Storing Eggs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/A - Storing Eggs.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/B - Magical Barrier.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/B - Magical Barrier.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/C - Nightmare Brother.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/C - Nightmare Brother.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/D - City Hall.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/D - City Hall.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/E - Substring Sort.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/E - Substring Sort.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/F - Doubled GCD.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/F - Doubled GCD.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/G - The Only Mode.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/G - The Only Mode.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/H - Grid Game.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/H - Grid Game.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/I - Contingency Plan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/I - Contingency Plan.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/J - Sharing Bread.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/J - Sharing Bread.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/K - Short Function.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/K - Short Function.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/L - Increase the Toll Fees.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/L - Increase the Toll Fees.pdf -------------------------------------------------------------------------------- /Competition/ICPC/2022/Final/Problem/M - Game Show.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Competition/ICPC/2022/Final/Problem/M - Game Show.pdf -------------------------------------------------------------------------------- /Competition/Meta Hacker Cup/Practice Round/A1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | using namespace std; 18 | 19 | #define ll long long 20 | #define ull unsigned long long 21 | #define bug(a) cout << a 22 | #define bugs(a) cout << a << ' ' 23 | #define debug(a) cout << a << endl 24 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 25 | 26 | void run_cases() { 27 | ll S, D, K; cin >> S >> D >> K; 28 | ll buns = (2 * S) + (D * 2); 29 | ll patties = S + (2 * D); 30 | ll kBuns = K + 1; 31 | ll kPatties = K; 32 | 33 | // cout << buns << " " << patties << " " << kBuns << " " << kPatties << endl; 34 | 35 | 36 | if((patties >= kPatties) and (buns >= kBuns)) { 37 | cout << "YES"; 38 | } else { 39 | cout << "NO"; 40 | } 41 | } 42 | 43 | int main() { 44 | boost; 45 | 46 | ll N; cin >> N; ll i = 1; 47 | while(N--) { 48 | cout << "Case #" << i << ": "; 49 | run_cases(); i++; 50 | cout << endl << flush; 51 | } 52 | 53 | return 0; 54 | } -------------------------------------------------------------------------------- /Competition/Meta Hacker Cup/Practice Round/A2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | void run_cases() { 7 | unsigned long long int A, B, C; cin >> A >> B >> C; 8 | unsigned long long int tempA = A, tempB = B, tempC = C; 9 | 10 | unsigned long long int singleCounter = 0, doubleCounter = 0, affordB = 0, affordA = 0; 11 | singleCounter = (tempC - (tempC % tempA)) / tempA; 12 | if(tempC - (singleCounter * tempA) >= tempB) { 13 | unsigned long long int temp = tempC - (singleCounter * tempA); 14 | affordB = (temp - (temp % tempB)) / tempB; 15 | } 16 | 17 | doubleCounter = (tempC - (tempC % tempB)) / tempB; 18 | if(tempC - (doubleCounter * tempB) >= tempA) { 19 | unsigned long long int temp = tempC - (doubleCounter * tempB); 20 | affordA = (temp - (temp % tempA)) / tempA; 21 | } 22 | 23 | // cerr << "singleCounter : " << singleCounter << endl; 24 | // cerr << "affordB : " << affordB << endl; 25 | // cerr << "doubleCounter : " << doubleCounter << endl; 26 | // cerr << "affordA : " << affordA << endl; 27 | 28 | 29 | // singleCounter : 100 30 | // affordB : 0 31 | // doubleCounter : 33 32 | // affordA : 1 33 | 34 | unsigned long long int bunsCase1 = (singleCounter * 2) + (affordB * 2); 35 | unsigned long long int pattiesCase1 = (singleCounter) + (affordB * 2); 36 | 37 | unsigned long long int bunsCase2 = (doubleCounter * 2) + (affordA * 2); 38 | unsigned long long int pattiesCase2 = (doubleCounter * 2) + (affordA); 39 | 40 | // cout << "bunsCase1 : " << bunsCase1 << endl; 41 | // cout << "pattiesCase1 : " << pattiesCase1 << endl; 42 | // cout << "bunsCase2 : " << bunsCase2 << endl; 43 | // cout << "pattiesCase2 : " << pattiesCase2 << endl; 44 | 45 | if(bunsCase1 == 0 and bunsCase2 > 0) { 46 | cout << bunsCase2 - 1; 47 | } else if(bunsCase2 == 0 and bunsCase1 > 0) { 48 | cout << bunsCase1 - 1; 49 | } else if(bunsCase1 > 0 and bunsCase2 > 0) { 50 | unsigned long long int kCase1, kCase2; 51 | (bunsCase1 > pattiesCase1) ? kCase1 = min(pattiesCase1, bunsCase1) : kCase1 = bunsCase1 - 1; 52 | (bunsCase2 > pattiesCase2) ? kCase2 = min(pattiesCase2, bunsCase2) : kCase2 = bunsCase2 - 1; 53 | 54 | // cout << kCase1 << " " << kCase2 << endl; 55 | 56 | cout << max(kCase1, kCase2); 57 | } else if(bunsCase1 == 0 and bunsCase2 == 0) { 58 | cout << "0"; 59 | } 60 | 61 | } 62 | 63 | int main() { 64 | unsigned long long int N; cin >> N; unsigned long long int i = 1; 65 | while(N--) { 66 | cout << "Case #" << i << ": "; 67 | run_cases(); i++; 68 | cout << endl; 69 | } 70 | 71 | return 0; 72 | } -------------------------------------------------------------------------------- /Competition/Meta Hacker Cup/Practice Round/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long int 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | bool isEven(ull x) { 30 | if(x % 2 == 0) { 31 | return true; 32 | } 33 | 34 | return false; 35 | } 36 | 37 | void run_cases() { 38 | ull R, C, A, B; cin >> R >> C >> A >> B; 39 | 40 | bool alice_wins = false; 41 | 42 | if(R == C) { 43 | alice_wins = false; 44 | } else if(R > C) { 45 | alice_wins = true; 46 | } else if(R < C) { 47 | alice_wins = false; 48 | } 49 | 50 | cout << ((alice_wins) ? "YES" : "NO"); 51 | } 52 | 53 | int main() { 54 | boost; 55 | 56 | unsigned long long int N; cin >> N; unsigned long long int i = 1; 57 | while(N--) { 58 | cout << "Case #" << i << ": "; 59 | run_cases(); i++; 60 | cout << endl; 61 | } 62 | 63 | return 0; 64 | } -------------------------------------------------------------------------------- /Competition/Meta Hacker Cup/Practice Round/C-temp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | #define ll long long 11 | #define ull unsigned long long 12 | #define bug(a) cout << a 13 | #define bugs(a) cout << a << ' ' 14 | #define debug(a) cout << a << endl 15 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 16 | 17 | template 18 | map count_map(vector &V) { 19 | map counter; 20 | for(auto &v : V) { 21 | counter[v]++; 22 | } 23 | 24 | return counter; 25 | } 26 | void run_cases() { 27 | ull N; cin >> N; N = (2 * N) - 1; 28 | vector apples(N); 29 | vector addedWeight; 30 | 31 | for(auto &apple : apples) { 32 | cin >> apple; 33 | } 34 | 35 | sort(apples.begin(), apples.end()); 36 | 37 | for(ull i = 0; i < N; i++) { 38 | for(int j = i + 1; j < N; j++) { 39 | addedWeight.push_back(apples[i] + apples[j]); 40 | } 41 | } 42 | 43 | map freq = count_map(addedWeight); 44 | ull freqAdd = 0, temp; 45 | for(const auto& pair : freq) { 46 | if(pair.second > freqAdd) { 47 | freqAdd = pair.second; 48 | temp = pair.first; 49 | } 50 | } 51 | 52 | bool breakPoint = true; ull leftPivot = 0, rightPivot = N - 1; ull leftout; 53 | while(breakPoint) { 54 | if((leftPivot == rightPivot)) { 55 | cout << temp - apples[leftPivot]; 56 | } else if(rightPivot - leftPivot == 1) { 57 | cout << temp - leftout; 58 | } else if((apples[leftPivot] + apples[rightPivot] != temp) and (apples[leftPivot + 1] + apples[rightPivot] == temp)) { 59 | leftout = apples[leftPivot]; 60 | leftPivot++; 61 | } else if((apples[leftPivot] + apples[rightPivot] != temp) and (apples[leftPivot] + apples[rightPivot - 1] == temp)) { 62 | leftout = apples[rightPivot]; 63 | rightPivot--; 64 | } 65 | } 66 | 67 | } 68 | 69 | int main() { 70 | boost; 71 | 72 | unsigned long long int N; cin >> N; unsigned long long int i = 1; 73 | while(N--) { 74 | cout << "Case #" << i << ": "; 75 | run_cases(); i++; 76 | cout << endl; 77 | } 78 | 79 | return 0; 80 | } -------------------------------------------------------------------------------- /Competition/Meta Hacker Cup/Practice Round/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | #define ull unsigned long long int 10 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 11 | 12 | void run_cases() { 13 | ull N; cin >> N; N = (2 * N) - 1; 14 | vector apples(N); 15 | 16 | for(auto &apple : apples) { 17 | cin >> apple; 18 | } 19 | 20 | sort(apples.begin(), apples.end()); 21 | 22 | ull ans; 23 | ull pivot = N - 1; 24 | ull temp = apples[pivot] + apples[0]; 25 | ull limit; 26 | bool ethical = true; 27 | ((N == 3) ? limit = 1 : limit = (N - 1) / 2); 28 | 29 | 30 | // 2 4 10 999999994 1000000000 31 | 32 | for(int i = 0; i <= limit; i++) { 33 | if((apples[i] + apples[pivot] != temp) and (i != (N - 1) / 2) and (i != 0)) { 34 | cout << -1; return; 35 | } else if((i == 0) and (apples[i + 1] + apples[pivot]) == (apples[i + 2] + apples[pivot - 1]) and N >= 5 and ((apples[i] + apples[pivot]) != (apples[i + 1] + apples[pivot - 1])) ) { 36 | temp = apples[i + 1] + apples[pivot]; i++; ethical = false; 37 | } else if(i == (N - 1) / 2 and pivot != i) { 38 | ans = temp - apples[i]; 39 | } else if(ethical == false) { 40 | cout << temp - apples[i]; 41 | } else if(apples[i] + apples[pivot] == temp) { 42 | pivot--; 43 | } 44 | } 45 | 46 | cout << ans; 47 | } 48 | 49 | int main() { 50 | boost; 51 | 52 | unsigned long long int N; cin >> N; unsigned long long int i = 1; 53 | while(N--) { 54 | cout << "Case #" << i << ": "; 55 | run_cases(); i++; 56 | cout << endl; 57 | } 58 | 59 | return 0; 60 | } 61 | 62 | 63 | 64 | // Case #1: 4 65 | // Case #2: 7 66 | // Case #3: 1 67 | // Case #4: -1 68 | // Case #5: 6 69 | // Case #6: -1 70 | // Case #7: 1000000002 71 | -------------------------------------------------------------------------------- /Competition/Meta Hacker Cup/Practice Round/output.txt: -------------------------------------------------------------------------------- 1 | Case #1: NO 2 | Case #2: NO 3 | Case #3: NO 4 | Case #4: NO 5 | Case #5: YES 6 | Case #6: YES 7 | Case #7: NO 8 | Case #8: NO 9 | Case #9: YES 10 | Case #10: YES 11 | Case #11: NO 12 | Case #12: NO 13 | Case #13: NO 14 | Case #14: YES 15 | Case #15: YES 16 | Case #16: NO 17 | Case #17: YES 18 | Case #18: NO 19 | Case #19: NO 20 | Case #20: NO 21 | Case #21: YES 22 | Case #22: NO 23 | Case #23: YES 24 | Case #24: YES 25 | Case #25: NO 26 | Case #26: NO 27 | Case #27: YES 28 | Case #28: YES 29 | Case #29: YES 30 | Case #30: NO 31 | Case #31: NO 32 | Case #32: YES 33 | Case #33: NO 34 | Case #34: NO 35 | Case #35: YES 36 | Case #36: NO 37 | Case #37: YES 38 | Case #38: NO 39 | Case #39: NO 40 | Case #40: NO 41 | Case #41: NO 42 | Case #42: NO 43 | Case #43: NO 44 | Case #44: YES 45 | Case #45: NO 46 | Case #46: NO 47 | Case #47: YES 48 | Case #48: NO 49 | Case #49: YES 50 | Case #50: NO 51 | Case #51: YES 52 | Case #52: NO 53 | Case #53: YES 54 | Case #54: YES 55 | Case #55: NO 56 | Case #56: YES 57 | Case #57: YES 58 | Case #58: YES 59 | Case #59: YES 60 | Case #60: NO 61 | Case #61: YES 62 | Case #62: YES 63 | Case #63: NO 64 | Case #64: YES 65 | Case #65: NO 66 | Case #66: NO 67 | Case #67: YES 68 | Case #68: NO 69 | Case #69: NO 70 | Case #70: YES 71 | Case #71: NO 72 | Case #72: NO 73 | Case #73: NO 74 | Case #74: NO 75 | Case #75: NO 76 | Case #76: YES 77 | Case #77: NO 78 | Case #78: YES 79 | Case #79: NO 80 | Case #80: NO 81 | Case #81: YES 82 | Case #82: NO 83 | Case #83: YES 84 | Case #84: NO 85 | Case #85: YES 86 | Case #86: YES 87 | Case #87: NO 88 | Case #88: NO 89 | Case #89: YES 90 | Case #90: NO 91 | Case #91: NO 92 | Case #92: NO 93 | Case #93: NO 94 | Case #94: NO 95 | Case #95: YES 96 | Case #96: NO 97 | Case #97: YES 98 | Case #98: YES 99 | Case #99: NO 100 | Case #100: YES 101 | Case #101: NO 102 | Case #102: NO 103 | Case #103: NO 104 | Case #104: YES 105 | Case #105: NO 106 | Case #106: YES 107 | Case #107: YES 108 | Case #108: NO 109 | Case #109: NO 110 | Case #110: NO 111 | Case #111: NO 112 | Case #112: NO 113 | Case #113: NO 114 | Case #114: NO 115 | Case #115: YES 116 | Case #116: YES 117 | Case #117: NO 118 | Case #118: YES 119 | Case #119: YES 120 | Case #120: YES 121 | Case #121: NO 122 | Case #122: NO 123 | Case #123: NO 124 | Case #124: YES 125 | Case #125: NO 126 | Case #126: NO 127 | Case #127: NO 128 | Case #128: YES 129 | Case #129: YES 130 | Case #130: NO 131 | Case #131: YES 132 | Case #132: NO 133 | Case #133: YES 134 | Case #134: YES 135 | Case #135: NO 136 | Case #136: NO 137 | Case #137: NO 138 | Case #138: YES 139 | Case #139: YES 140 | Case #140: YES 141 | Case #141: NO 142 | Case #142: YES 143 | Case #143: NO 144 | Case #144: YES 145 | Case #145: NO 146 | Case #146: NO 147 | Case #147: NO 148 | Case #148: NO 149 | Case #149: YES 150 | Case #150: NO 151 | Case #151: NO 152 | Case #152: YES 153 | Case #153: YES 154 | Case #154: NO 155 | Case #155: YES 156 | Case #156: YES 157 | Case #157: NO 158 | Case #158: YES 159 | Case #159: NO 160 | Case #160: YES 161 | Case #161: NO 162 | Case #162: NO 163 | Case #163: NO 164 | Case #164: YES 165 | Case #165: YES 166 | Case #166: NO 167 | Case #167: YES 168 | Case #168: NO 169 | Case #169: NO 170 | Case #170: YES 171 | Case #171: NO 172 | Case #172: NO 173 | Case #173: YES 174 | Case #174: NO 175 | Case #175: NO 176 | Case #176: YES 177 | Case #177: NO 178 | Case #178: YES 179 | Case #179: NO 180 | Case #180: YES 181 | Case #181: YES 182 | Case #182: NO 183 | Case #183: NO 184 | Case #184: NO 185 | Case #185: NO 186 | Case #186: NO 187 | Case #187: NO 188 | Case #188: NO 189 | Case #189: YES 190 | Case #190: NO 191 | Case #191: YES 192 | Case #192: YES 193 | Case #193: YES 194 | Case #194: NO 195 | Case #195: YES 196 | Case #196: NO 197 | Case #197: NO 198 | Case #198: YES 199 | Case #199: NO 200 | Case #200: NO 201 | Case #201: NO 202 | Case #202: NO 203 | Case #203: NO 204 | Case #204: NO 205 | Case #205: NO 206 | Case #206: NO 207 | Case #207: NO 208 | Case #208: NO 209 | Case #209: YES 210 | Case #210: NO 211 | Case #211: NO 212 | Case #212: YES 213 | Case #213: NO 214 | Case #214: NO 215 | Case #215: NO 216 | Case #216: YES 217 | Case #217: YES 218 | Case #218: YES 219 | Case #219: YES 220 | Case #220: NO 221 | Case #221: NO 222 | Case #222: NO 223 | Case #223: NO 224 | Case #224: NO 225 | Case #225: NO 226 | Case #226: YES 227 | Case #227: NO 228 | Case #228: NO 229 | Case #229: YES 230 | Case #230: NO 231 | Case #231: YES 232 | Case #232: YES 233 | Case #233: NO 234 | Case #234: YES 235 | Case #235: YES 236 | Case #236: NO 237 | Case #237: YES 238 | Case #238: NO 239 | Case #239: NO 240 | Case #240: NO 241 | Case #241: NO 242 | Case #242: NO 243 | Case #243: YES 244 | Case #244: YES 245 | Case #245: NO 246 | Case #246: NO 247 | Case #247: NO 248 | Case #248: YES 249 | Case #249: NO 250 | Case #250: NO 251 | Case #251: YES 252 | Case #252: NO 253 | Case #253: YES 254 | Case #254: YES 255 | Case #255: YES 256 | Case #256: YES 257 | Case #257: YES 258 | Case #258: NO 259 | Case #259: YES 260 | Case #260: NO 261 | Case #261: YES 262 | Case #262: NO 263 | Case #263: NO 264 | Case #264: NO 265 | Case #265: NO 266 | Case #266: NO 267 | Case #267: NO 268 | Case #268: NO 269 | Case #269: NO 270 | Case #270: YES 271 | Case #271: NO 272 | Case #272: YES 273 | Case #273: NO 274 | Case #274: NO 275 | Case #275: NO 276 | Case #276: YES 277 | Case #277: YES 278 | Case #278: NO 279 | Case #279: YES 280 | Case #280: NO 281 | Case #281: NO 282 | Case #282: NO 283 | Case #283: NO 284 | Case #284: NO 285 | Case #285: NO 286 | Case #286: YES 287 | Case #287: YES 288 | Case #288: YES 289 | Case #289: NO 290 | Case #290: NO 291 | Case #291: NO 292 | Case #292: YES 293 | Case #293: NO 294 | Case #294: YES 295 | Case #295: NO 296 | Case #296: YES 297 | Case #297: YES 298 | Case #298: NO 299 | Case #299: NO 300 | Case #300: YES 301 | Case #301: YES 302 | Case #302: NO 303 | Case #303: YES 304 | Case #304: NO 305 | Case #305: YES 306 | Case #306: NO 307 | Case #307: YES 308 | Case #308: YES 309 | Case #309: YES 310 | Case #310: NO 311 | Case #311: NO 312 | Case #312: NO 313 | Case #313: NO 314 | Case #314: YES 315 | Case #315: NO 316 | Case #316: YES 317 | Case #317: YES 318 | Case #318: YES 319 | Case #319: NO 320 | Case #320: YES 321 | Case #321: NO 322 | Case #322: NO 323 | Case #323: YES 324 | Case #324: NO 325 | Case #325: YES 326 | Case #326: NO 327 | Case #327: YES 328 | Case #328: NO 329 | Case #329: NO 330 | Case #330: NO 331 | Case #331: YES 332 | Case #332: YES 333 | Case #333: YES 334 | Case #334: YES 335 | Case #335: YES 336 | Case #336: NO 337 | Case #337: NO 338 | Case #338: YES 339 | Case #339: NO 340 | Case #340: NO 341 | Case #341: NO 342 | Case #342: NO 343 | Case #343: NO 344 | Case #344: YES 345 | Case #345: NO 346 | Case #346: NO 347 | Case #347: NO 348 | Case #348: YES 349 | Case #349: NO 350 | Case #350: YES 351 | Case #351: YES 352 | Case #352: NO 353 | Case #353: NO 354 | Case #354: YES 355 | Case #355: NO 356 | Case #356: NO 357 | Case #357: NO 358 | Case #358: YES 359 | Case #359: YES 360 | Case #360: NO 361 | Case #361: NO 362 | Case #362: NO 363 | Case #363: NO 364 | Case #364: YES 365 | Case #365: NO 366 | Case #366: YES 367 | Case #367: NO 368 | Case #368: YES 369 | Case #369: NO 370 | Case #370: YES 371 | Case #371: YES 372 | Case #372: YES 373 | Case #373: YES 374 | Case #374: YES 375 | Case #375: NO 376 | Case #376: NO 377 | Case #377: YES 378 | Case #378: YES 379 | Case #379: NO 380 | Case #380: YES 381 | Case #381: NO 382 | Case #382: YES 383 | Case #383: YES 384 | Case #384: NO 385 | Case #385: YES 386 | Case #386: NO 387 | Case #387: NO 388 | Case #388: YES 389 | Case #389: NO 390 | Case #390: NO 391 | Case #391: YES 392 | Case #392: YES 393 | Case #393: YES 394 | Case #394: YES 395 | Case #395: NO 396 | Case #396: YES 397 | Case #397: YES 398 | Case #398: NO 399 | Case #399: NO 400 | Case #400: NO 401 | Case #401: NO 402 | Case #402: NO 403 | Case #403: NO 404 | Case #404: NO 405 | Case #405: YES 406 | Case #406: NO 407 | Case #407: YES 408 | Case #408: NO 409 | Case #409: YES 410 | Case #410: YES 411 | Case #411: NO 412 | Case #412: YES 413 | Case #413: NO 414 | Case #414: NO 415 | Case #415: NO 416 | Case #416: NO 417 | Case #417: YES 418 | Case #418: NO 419 | Case #419: YES 420 | Case #420: YES 421 | Case #421: NO 422 | Case #422: YES 423 | Case #423: YES 424 | Case #424: YES 425 | Case #425: NO 426 | Case #426: NO 427 | Case #427: NO 428 | Case #428: YES 429 | Case #429: NO 430 | Case #430: YES 431 | Case #431: YES 432 | Case #432: NO 433 | Case #433: NO 434 | Case #434: NO 435 | Case #435: NO 436 | Case #436: NO 437 | Case #437: YES 438 | Case #438: YES 439 | Case #439: NO 440 | Case #440: NO 441 | Case #441: YES 442 | Case #442: NO 443 | Case #443: NO 444 | Case #444: NO 445 | Case #445: YES 446 | Case #446: NO 447 | Case #447: YES 448 | Case #448: YES 449 | Case #449: YES 450 | Case #450: NO 451 | Case #451: NO 452 | Case #452: NO 453 | Case #453: YES 454 | Case #454: NO 455 | Case #455: YES 456 | Case #456: NO 457 | Case #457: NO 458 | Case #458: NO 459 | Case #459: NO 460 | Case #460: NO 461 | Case #461: NO 462 | Case #462: NO 463 | Case #463: NO 464 | Case #464: NO 465 | Case #465: NO 466 | Case #466: YES 467 | Case #467: YES 468 | Case #468: YES 469 | Case #469: NO 470 | Case #470: NO 471 | Case #471: NO 472 | Case #472: NO 473 | Case #473: YES 474 | Case #474: NO 475 | Case #475: YES 476 | Case #476: NO 477 | Case #477: YES 478 | Case #478: NO 479 | Case #479: YES 480 | Case #480: NO 481 | Case #481: NO 482 | Case #482: YES 483 | Case #483: YES 484 | Case #484: YES 485 | Case #485: NO 486 | Case #486: YES 487 | Case #487: NO 488 | Case #488: NO 489 | Case #489: NO 490 | Case #490: NO 491 | Case #491: YES 492 | Case #492: YES 493 | Case #493: NO 494 | Case #494: YES 495 | Case #495: YES 496 | Case #496: YES 497 | Case #497: NO 498 | Case #498: NO 499 | Case #499: YES 500 | Case #500: NO 501 | -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a, b; cin >> a >> b; 6 | cout << a + b << endl; 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/10.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | vector v; 7 | string temp; 8 | 9 | while(cin >> temp) { 10 | v.push_back(temp); 11 | } 12 | 13 | for(auto &r : v) { 14 | cout << r << endl; 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | float a, b; cin >> a >> b; 7 | cout << fixed << setprecision(2) << (a * b) / 2; 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() { 4 | int n; cin >> n; 5 | 6 | if(n < 10) cout << "satuan"; 7 | else if(n < 100) cout << "puluhan"; 8 | else if(n < 1000) cout << "ratusan"; 9 | else if(n < 10000) cout << "ribuan"; 10 | else if (n < 100000) cout << "puluhribuan"; 11 | return 0; 12 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int N; cin >> N; 6 | 7 | for(int i = N; i > 0; i--) { 8 | if(N % i == 0) cout << i << endl; 9 | } 10 | return 0; 11 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int array[3][3]; 6 | for(int i = 0; i < 3; i++) 7 | for(int j = 0; j < 3; j++) 8 | cin >> array[i][j]; 9 | 10 | for(int i = 0; i < 3; i++) { 11 | for(int j = 0; j < 3; j++) 12 | {cout << array[j][i] << " ";} 13 | 14 | cout << endl; 15 | } 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int N; cin >> N; 6 | int total = 0, temp; 7 | 8 | while(N--) { 9 | cin >> temp; 10 | total += temp; 11 | } 12 | 13 | cout << total; 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int N; cin >> N; 8 | 9 | vector v(N); 10 | 11 | for(auto &x : v) { 12 | cin >> x; 13 | } 14 | 15 | sort(v.begin(), v.end()); 16 | cout << v[N -1] << " " << v[0]; 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/8.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool prima(int n) { 5 | if(n <= 1) return false; 6 | 7 | if(n <= 3) return true; 8 | 9 | if(n % 2 == 0 || n % 3 == 0) return false; 10 | 11 | for(int i = 5; i * i <= n; i+=6) { 12 | if(n % i == 0 or n % (i + 2) == 0) { 13 | return false; 14 | } 15 | } 16 | 17 | return true; 18 | 19 | } 20 | 21 | int main() { 22 | int N, temp; cin >> N; 23 | 24 | while(N--) { 25 | cin >> temp; 26 | if(prima(temp)) { 27 | cout << "YA" << endl; 28 | } else { 29 | cout << "BUKAN" << endl; 30 | } 31 | } 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Competition/Pekan-IT UNSIKA/9.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int N; cin >> N; 6 | 7 | for(int i = 1; i <= N; i++) { 8 | if(i % 10 == 0) { 9 | continue; 10 | } else if(i == 42) { 11 | cout << "ERROR"; break; 12 | } else { 13 | cout << i << endl; 14 | } 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Learning Material/Competitive Programming Handbook.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Learning Material/Competitive Programming Handbook.pdf -------------------------------------------------------------------------------- /Learning Material/Pemrograman Kompetitif Dasar TOKI.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Learning Material/Pemrograman Kompetitif Dasar TOKI.pdf -------------------------------------------------------------------------------- /Learning Progress/CSES/missing_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define all(a) a.begin(), a.end() 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int main() { 29 | boost; 30 | 31 | ull N; cin >> N; 32 | 33 | int arr[N - 1]; 34 | 35 | for(int i = 0; i < N - 1; i++) { 36 | cin >> arr[i]; 37 | } 38 | 39 | sort(arr, arr + N); 40 | 41 | for(int i = 0; i < N - 2; i++) { 42 | if(arr[i + 1] - arr[i] != 1) { 43 | cout << arr[i] + 1; 44 | } 45 | } 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Learning Progress/CSES/weird_algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define all(a) a.begin(), a.end() 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int main() { 29 | boost; 30 | 31 | ull N; cin >> N; 32 | 33 | while(N != 1) { 34 | cout << N << " "; 35 | if(N % 2 == 0) { 36 | N /= 2; 37 | } else { 38 | N = (N * 3) + 1; 39 | } 40 | } 41 | 42 | cout << 1; 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Gemastik 2023/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define all(a) a.begin(), a.end() 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int find(int x, vector &ans) { 29 | for(int i = 0; i < ans.size(); i++) { 30 | if(ans[i] == x) return i + 1; 31 | } 32 | } 33 | 34 | bool hasDuplicate(const std::vector& vec, int element) { 35 | int count = 0; 36 | for (int num : vec) { 37 | if (num == element) { 38 | count++; 39 | if (count > 1) { 40 | return true; // Element appears more than once 41 | } 42 | } 43 | } 44 | return false; // Element appears only once or not at all 45 | } 46 | 47 | int main() { 48 | boost; 49 | 50 | int N; cin >> N; 51 | vector cup(N); 52 | for(int &x : cup) { 53 | cin >> x; 54 | } 55 | 56 | vector cupCp = cup; 57 | sort(cup.begin(), cup.end()); 58 | cup.erase(unique(all(cup)), cup.end()); 59 | 60 | if(cup.size() == 1) cout << "SESUAI"; 61 | else if(cup.size() == 2 and N == 2) { 62 | cout << (abs(cup[0] - cup[1])) / 2 << " "; 63 | cout << find(cup[1], cupCp) << " " << find((cup[0]), cupCp); 64 | } else if(cup.size() == 3 and !hasDuplicate(cupCp, cup[0]) and !hasDuplicate(cupCp, cup[2]) and (cup[0] + cup[2]) == (cup[1] * 2)) { 65 | cout << cup[2] - cup[1] << " "; 66 | cout << find(cup[2], cupCp) << " " << find(cup[0], cupCp); 67 | } else { 68 | cout << "TIDAK SESUAI"; 69 | } 70 | 71 | return 0; 72 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/1/1A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | cout << "Halo, dunia!"; 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/10/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int main() { 29 | boost; 30 | 31 | int n; cin >> n; 32 | int v1[n]; 33 | int v2[n]; 34 | 35 | for(auto &v : v1) { 36 | cin >> v; 37 | } 38 | 39 | for(auto &v : v2) { 40 | cin >> v; 41 | } 42 | 43 | int t; cin >> t; 44 | while(t--) { 45 | char p, q; int a, b; 46 | cin >> p >> a >> q >> b; 47 | 48 | if(p == 'A' and q == 'B') 49 | swap(v1[a - 1], v2[b - 1]); 50 | else if(p == 'B' and q == 'A') 51 | swap(v2[a - 1], v1[b - 1]); 52 | else if(p == 'A' and q == 'A') 53 | swap(v1[a - 1], v1[b - 1]); 54 | else if(p == 'B' and q == 'B') 55 | swap(v2[a - 1], v2[b - 1]); 56 | } 57 | 58 | for(auto &v : v1) { 59 | cout << v << " "; 60 | } 61 | 62 | cout << endl; 63 | 64 | for(auto &v : v2) { 65 | cout << v << " "; 66 | } 67 | 68 | return 0; 69 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/10/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int reverse(int x) { 29 | int temp = x, ret = 0; 30 | 31 | while(temp > 0) { 32 | ret = (ret * 10) + (temp % 10); 33 | temp /= 10; 34 | } 35 | 36 | return ret; 37 | 38 | } 39 | 40 | int main() { 41 | boost; 42 | 43 | int a, b; cin >> a >> b; 44 | 45 | int c = reverse(a) + reverse(b); 46 | c = reverse(c); 47 | cout << c; 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/10/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | void solve() { 29 | 30 | } 31 | 32 | void solve(int x) { 33 | for(int i = 2; i < sqrt(x); i++) { 34 | int temp = 0; 35 | bool flag = false; 36 | while(x % i == 0) { 37 | temp++; 38 | x /= i; 39 | flag = true; 40 | } 41 | 42 | if(flag) { 43 | cout << i; 44 | 45 | if(temp > 1) { 46 | cout << '^' << temp; 47 | } 48 | 49 | if(x > 1) { 50 | cout << " x "; 51 | } 52 | } 53 | } 54 | 55 | if(x > 1) { 56 | cout << x; 57 | } 58 | 59 | } 60 | 61 | int main() { 62 | boost; 63 | 64 | int n; cin >> n; 65 | solve(n); 66 | 67 | return 0; 68 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/10/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int A, B, K; 29 | 30 | int Func(int x) { 31 | return abs((A * x) + B); 32 | } 33 | 34 | int main() { 35 | boost; 36 | 37 | int x; 38 | cin >> A >> B >> K >> x; 39 | 40 | for(int i = 1; i <= K; i++) { 41 | x = Func(x); 42 | } 43 | 44 | cout << x; 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/10/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int Func(int Xj, int Xi, int Yj, int Yi, int D) { 30 | return (int)pow(abs(Xj - Xi), D) + (int)pow(abs(Yj - Yi), D); 31 | } 32 | 33 | int main() { 34 | boost; 35 | 36 | int N, D, maxT = INT_MIN, minT = INT_MAX; cin >> N >> D; 37 | 38 | vector> v; 39 | for(int i = 0; i < N; i++) { 40 | int a, b; 41 | cin >> a >> b; 42 | v.emplace_back(a, b); 43 | } 44 | 45 | for(int i = 0; i < N - 1; i++) { 46 | for(int j = i + 1; j < N; j++) { 47 | maxT = max(maxT, Func(v[j].first, v[i].first, v[j].second, v[i].second, D)); 48 | minT = min(minT, Func(v[j].first, v[i].first, v[j].second, v[i].second, D)); 49 | } 50 | } 51 | 52 | cout << minT << " " << maxT; 53 | 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/11/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | string s, t; 33 | cin >> s >> t; 34 | 35 | while(s.find(t) != -1) { 36 | s.erase(s.find(t), t.length()); 37 | } 38 | 39 | cout << s; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/11/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | string s, ans = ""; int k; cin >> s >> k; 33 | for(int i = 0; s[i]; i++) { 34 | if(s[i] + k > 122) { 35 | ans += (char)(s[i] + k - 122 + 96); 36 | } else ans += (char)(s[i] + k); 37 | } 38 | 39 | cout << ans; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/11/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | string S1, S2, S3, S4; 33 | cin >> S1 >> S2 >> S3 >> S4; 34 | 35 | S1.erase(S1.find(S2), S2.length()); 36 | S1.insert(S1.find(S3) + S3.length(), S4); 37 | 38 | cout << S1; 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/11/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | string s, ans = ""; 33 | cin >> s; 34 | for(int i = 0; s[i]; i++) { 35 | if(islower(s[i])) { 36 | ans += (char)(s[i] - 32); 37 | } else { 38 | ans += (char)(s[i] + 32); 39 | } 40 | } 41 | 42 | cout << ans; 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/11/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | string s; cin >> s; 33 | string ans = ""; 34 | if(s.find("_") != -1) { 35 | for(int i = 0; s[i]; i++) { 36 | if(s[i] == '_') { 37 | i++; 38 | ans += (char)(s[i] - 32); 39 | } else ans += s[i]; 40 | } 41 | 42 | cout << ans; 43 | } else { 44 | for(int i = 0; s[i]; i++) { 45 | if(isupper(s[i])) { 46 | ans += "_"; 47 | ans += (char)(s[i] + 32); 48 | } else ans += s[i]; 49 | } 50 | 51 | cout << ans; 52 | } 53 | 54 | return 0; 55 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/12/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int rekursiGanjilGenap(int x) { 30 | if(x == 1 or x == 0) { 31 | return 1; 32 | } else if(x % 2 == 0) { 33 | return x * rekursiGanjilGenap(x - 1) / 2; 34 | } else { 35 | return x * rekursiGanjilGenap(x - 1); 36 | } 37 | } 38 | 39 | int main() { 40 | boost; 41 | 42 | int n; cin >> n; 43 | cout << rekursiGanjilGenap(n); 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/12/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int A, B, x; 30 | int recursiveFunc(int k) { 31 | if(k == 0) { 32 | return x; 33 | } else { 34 | return abs(A * recursiveFunc(k - 1) + B); 35 | } 36 | } 37 | 38 | int main() { 39 | boost; 40 | 41 | int K; 42 | cin >> A >> B >> K >> x; 43 | 44 | cout << recursiveFunc(K); 45 | 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/12/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | // string palindrome(string s, int a, int b) { 30 | // if(s == '') { 31 | // return "YA"; 32 | // } else if(s) 33 | // } 34 | 35 | bool palindrom(string s) { 36 | int len = s.length(); 37 | if(len < 2) { 38 | return true; 39 | } else if(s[0] == s[len - 1]) { 40 | s.erase(len - 1, 1); 41 | s.erase(0, 1); 42 | return palindrom(s); 43 | } else { 44 | return false; 45 | } 46 | 47 | } 48 | 49 | int main() { 50 | boost; 51 | 52 | string s; cin >> s; 53 | if(palindrom(s)) { 54 | cout << "YA"; 55 | } else { 56 | cout << "BUKAN"; 57 | } 58 | 59 | // cout << palindrome(s, 0, s.length() - 1); 60 | 61 | return 0; 62 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/12/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | string ans = ""; 30 | 31 | string biner(int x) { 32 | if(x == 1) return "1"; 33 | else if(x % 2 == 0) return biner(x/2) + "0"; 34 | else return biner(x/2) + "1"; 35 | } 36 | 37 | int main() { 38 | boost; 39 | 40 | int x; bool flag = true; cin >> x; 41 | ans = biner(x); 42 | 43 | cout << ans; 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/13/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | void draw(int n) { 30 | if(n > 0) { 31 | draw(n - 1); 32 | for(int i = 1; i <= n; i++) { 33 | cout << "*"; 34 | } cout << endl; 35 | draw(n - 1); 36 | } 37 | } 38 | 39 | int main() { 40 | boost; 41 | 42 | int n; cin >> n; 43 | 44 | draw(n); 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/13/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | using namespace std; 22 | 23 | #define ll long long 24 | #define ull unsigned long long 25 | #define bug(a) cout << a 26 | #define bugs(a) cout << a << ' ' 27 | #define debug(a) cout << a << endl 28 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 29 | 30 | int n; 31 | int catat[100]; 32 | bool pernah[100] = {false}; 33 | 34 | void tulis(int kedalaman) { 35 | if(kedalaman > n) { 36 | bool zigzag; 37 | for(int i = 2; i <= n - 1; i++) { 38 | if(catat[i] > catat[i - 1] and catat[i] > catat[i + 1] or catat[i] < catat[i - 1] and catat[i] < catat[i + 1]) { 39 | zigzag = true; 40 | } else { 41 | zigzag = false; 42 | break; 43 | } 44 | } 45 | 46 | if(zigzag) { 47 | for(int i = 1; i <= n; i++) { 48 | cout << catat[i]; 49 | } 50 | 51 | cout << endl; 52 | } 53 | } else { 54 | for(int i = 1; i <= n; i+=1) { 55 | if(!pernah[i]) { 56 | pernah[i] = true; 57 | catat[kedalaman] = i; 58 | tulis(kedalaman + 1); 59 | pernah[i] = false; 60 | } 61 | } 62 | } 63 | } 64 | 65 | int main() { 66 | 67 | cin >> n; 68 | 69 | tulis(1); 70 | 71 | 72 | return 0; 73 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/13/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int n, k, dp[10]; 5 | 6 | void pwbreak(int x) { 7 | if(x >= k) { 8 | for(int i = 0; i < k; i++) { 9 | cout << dp[i] << ' '; 10 | } 11 | 12 | cout << endl; 13 | } else { 14 | for(int i = dp[x - 1] + 1; i <= n; i++) { 15 | dp[x] = i; 16 | pwbreak(x + 1); 17 | } 18 | } 19 | } 20 | 21 | int main() { 22 | cin >> n >> k; 23 | pwbreak(0); 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/13/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 6 | 7 | int m[128][128]; 8 | int nJawaban; 9 | string jawaban[128*128]; 10 | 11 | bool homogen(int r, int c, int k) { 12 | int val = m[r][c]; 13 | for(int i = r; i < r + k; i++) { 14 | for(int j = c; j < c + k; j++) { 15 | if(m[i][j] != val) 16 | return false; 17 | } 18 | } 19 | 20 | return true; 21 | } 22 | 23 | // Kodekan submatrix [r, c, r + k - 1, c + k - 1] 24 | void quadtree(int r, int c, int k, string s) { 25 | if(homogen(r, c, k)) { 26 | if(m[r][c] == 1) { 27 | jawaban[nJawaban] = "1" + s; 28 | nJawaban++; 29 | } 30 | } else { 31 | quadtree(r, c, k / 2, s + "0"); 32 | quadtree(r, c + k / 2, k / 2, s + "1"); 33 | quadtree(r + k / 2, c, k / 2, s + "2"); 34 | quadtree(r + k / 2, c + k / 2, k / 2, s + "3"); 35 | 36 | } 37 | } 38 | 39 | int main() { 40 | boost; 41 | 42 | int R, C; 43 | cin >> R >> C; 44 | 45 | int maxRC = max(R, C), pow2 = 1; 46 | while(pow2 < maxRC) { 47 | pow2 *= 2; 48 | } 49 | 50 | for(int i = 0; i < pow2; i++) 51 | for(int j = 0; j < pow2; j++) 52 | m[i][j] = 0; 53 | 54 | for(int i = 0; i < R; i++) 55 | for(int j = 0; j < C; j++) 56 | cin >> m[i][j]; 57 | 58 | nJawaban = 0; 59 | quadtree(0, 0, pow2, ""); 60 | 61 | cout << nJawaban << endl; 62 | for(int i = 0; i < nJawaban; i++) { 63 | cout << jawaban[i] << endl; 64 | } 65 | 66 | return 0; 67 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/13/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int m[128][128]; 7 | 8 | void transform(int r, int c, int k, int index, string s) { 9 | if(index == s.length()) { 10 | for(int i = r; i < r + k; i++) { 11 | for(int j = c; j < c + k; j++) { 12 | m[i][j] = 1; 13 | } 14 | } 15 | } else { 16 | if(s[index] == '0') transform(r, c, k/2, index + 1, s); 17 | else if(s[index] == '1') transform(r, c + k / 2, k / 2, index + 1, s); 18 | else if(s[index] == '2') transform(r + k / 2, c, k / 2, index + 1, s); 19 | else transform(r + k / 2, c + k / 2, k / 2, index + 1, s); 20 | } 21 | } 22 | 23 | int main() { 24 | int n; cin >> n; 25 | string biner[n]; 26 | for(int i = 0; i < n; i++) { 27 | cin >> biner[i]; 28 | } 29 | 30 | int r, c; cin >> r >> c; 31 | int pow = 1; 32 | 33 | while(pow < max(r,c)) 34 | pow *= 2; 35 | 36 | for(int i = 0; i < pow; i++) { 37 | for(int j = 0; j < pow; j++) { 38 | m[i][j] = 0; 39 | } 40 | } 41 | 42 | for(int i = 0; i < n; i++) { 43 | string s = biner[i]; 44 | transform(0, 0, pow, 1, s); 45 | } 46 | 47 | for(int i = 0; i < r; i++) { 48 | for(int j = 0; j < c; j++) { 49 | cout << m[i][j] << ' '; 50 | } 51 | 52 | cout << endl; 53 | } 54 | 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/13/G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 6 | 7 | int pindahx[] = {0, 0, 1, -1}; 8 | int pindahy[] = {1, -1, 0, 0}; 9 | int nilai; 10 | int bola[25][25]; 11 | int M, N; 12 | 13 | void hitung(int x, int y, int awal) { 14 | if((bola[x][y] != awal) or (y < 0) or (x < 0) or (y >= 25) or (x >= 25)) { 15 | return; 16 | } else { 17 | nilai++; 18 | // cout << endl << nilai << endl; 19 | bola[x][y] = -1; 20 | for(int i = 0; i < 4; i++) { 21 | hitung(x + pindahx[i], y + pindahy[i], awal); 22 | } 23 | } 24 | } 25 | 26 | int main() { 27 | boost; 28 | nilai = 0; 29 | cin >> M >> N; 30 | 31 | for(int i = 0; i < M; i++) { 32 | for(int j = 0; j < N; j++) { 33 | cin >> bola[i][j]; 34 | } 35 | } 36 | 37 | int B, K; cin >> B >> K; 38 | hitung(B, K, bola[B][K]); 39 | cout << ((nilai - 1) * nilai) << endl; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/3/3B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int a, b; 6 | cin >> a >> b; 7 | cout << a + b; 8 | 9 | return 0; 10 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/3/3C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | string lope; 14 | getline(cin, lope); 15 | cout << lope; 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/3/3D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int a, b; 14 | cin >> a >> b; 15 | 16 | cout << "masing-masing " << a / b; 17 | cout << "\nbersisa " << a % b; 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/3/3E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | double A, T; 14 | cin >> A >> T; 15 | 16 | cout << fixed << setprecision(2) << A * T / 2; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/3/3F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int array[3][3]; 14 | 15 | for(int i = 0; i < 3; i++) 16 | for(int j = 0; j < 3; j++) 17 | cin >> array[i][j]; 18 | 19 | 20 | for(int i = 0; i < 3; i++) { 21 | for(int j = 0; j < 3; j++) 22 | cout << array[j][i] << " "; 23 | 24 | cout << endl; 25 | } 26 | 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/5/5B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n; cin >> n; 14 | if(n > 0) cout << n; 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/5/5C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n; cin >> n; 14 | if(n > 0 and n % 2 == 0) cout << n; 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/5/5D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n; cin >> n; 14 | if(n > 0) cout << "positif"; 15 | else if(n < 0) cout << "negatif"; 16 | else cout << "nol"; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/5/5E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n; cin >> n; 14 | if(n > 9999) cout << "puluhribuan"; 15 | else if(n > 999) cout << "ribuan"; 16 | else if(n > 99) cout << "ratusan"; 17 | else if(n > 9) cout << "puluhan"; 18 | else cout << "satuan"; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/5/5F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | double n; cin >> n; 14 | if(trunc(n) == n) cout << (int)n << " " << (int)n; 15 | else if(n < 0) cout << (int)trunc(n) - 1 << " " << (int)trunc(n); 16 | else if(n > 0) cout << (int)trunc(n) << " " << (int)trunc(n) + 1; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/5/5G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int a, b, c, d; 14 | cin >> a >> b >> c >> d; 15 | cout << abs(a - c) + abs(b - d); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n; cin >> n; 14 | int jumlah = 0; 15 | for(int i = 0; i < n; i++) { 16 | int temp; cin >> temp; 17 | jumlah += temp; 18 | } 19 | 20 | cout << jumlah << endl; 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | string temp; 14 | while(getline(cin, temp)) 15 | cout << temp << endl; 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int temp, jumlah = 0; 14 | while(cin >> temp) { 15 | jumlah += temp; 16 | } 17 | 18 | cout << jumlah << endl; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int maxN = INT_MAX, minN = INT_MIN, n; 14 | cin >> n; 15 | 16 | while(n--) { 17 | int temp; cin >> temp; 18 | maxN = max(maxN, temp); minN = min(minN, temp); 19 | } 20 | 21 | cout << maxN << " " << minN; 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n; cin >> n; 14 | for(int i = n; i != 1; i--) { 15 | if(n % i == 0) cout << i << endl; 16 | } 17 | 18 | cout << "1"; 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int maxN = INT_MIN, minN = INT_MAX, n; 14 | cin >> n; 15 | 16 | while(n--) { 17 | int temp; cin >> temp; 18 | maxN = max(maxN, temp); minN = min(minN, temp); 19 | } 20 | 21 | cout << maxN << " " << minN; 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/6/6H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n, k; cin >> n >> k; 14 | for(int i = 1; i <= n; i++) { 15 | if(i % k == 0) cout << "* "; 16 | else cout << i << " "; 17 | } 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/7/7A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N; cin >> N; 14 | for(int i = 1; i <= N; i++) { 15 | if(i % 10 == 0) continue; 16 | else if(i == 42) { 17 | cout << "ERROR" << endl; 18 | break; 19 | } 20 | 21 | cout << i << endl; 22 | } 23 | 24 | 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/7/7B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N; cin >> N; 14 | 15 | for(int i = 0; i < N; i++) { 16 | for(int j = 0; j < N; j++) { 17 | if(j < N - i - 1) cout << " "; 18 | else cout << "*"; 19 | 20 | } 21 | cout << endl; 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/7/7C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N, temp = 0; cin >> N; 14 | 15 | for(int i = 0; i < N; i++) { 16 | for(int j = 0; j < i + 1; j++) { 17 | if(temp == 10) temp = 0; 18 | 19 | cout << temp; temp++; 20 | } 21 | cout << endl; 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/8/8B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | string primeCheck(int kontol) { 6 | if(kontol == 1) return "BUKAN"; 7 | 8 | for(int i = 2; i <= sqrt(kontol); i+=1) { 9 | if(kontol % i == 0) return "BUKAN"; 10 | } 11 | 12 | return "YA"; 13 | } 14 | 15 | int main() { 16 | int N, input; 17 | cin >> N; 18 | while(N--) { 19 | cin >> input; 20 | string ganteng = primeCheck(input); 21 | cout << ganteng << endl; 22 | } 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/8/8C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 4 | using namespace std; 5 | 6 | string agakPrimeChecker(int input) { 7 | int count = 0; 8 | if(input == 1) return "YA"; 9 | 10 | for(int i = 2; i < input; i++) { 11 | if(input % i == 0) count++; 12 | 13 | if(count >= 3) return "BUKAN"; 14 | } 15 | 16 | return "YA"; 17 | } 18 | 19 | int main() { 20 | boost; 21 | 22 | int N, input; cin >> N; 23 | 24 | while(N--) { 25 | cin >> input; 26 | string answer = agakPrimeChecker(input); 27 | cout << answer << endl; 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/9/9B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | const int maxSize = 100; // Maksimal jumlah bilangan 6 | int numbers[maxSize]; 7 | int num; 8 | int count = 0; 9 | 10 | while (cin >> numbers[count]) { 11 | ++count; 12 | } 13 | 14 | // Mencetak bilangan-bilangan dalam urutan terbalik 15 | for (int i = count - 1; i >= 0; i--) { 16 | cout << numbers[i] << endl; 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/9/9C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int main() { 29 | boost; 30 | 31 | int n; cin >> n; 32 | vector> v; 33 | for(int i = 0; i < n; i++) { 34 | int temp; 35 | cin >> temp; 36 | 37 | } 38 | 39 | 40 | 41 | // int n; cin >> n; 42 | // map mapping; 43 | // for(int i = 0; i < n; i++) { 44 | // int temp; cin >> temp; 45 | // mapping[temp]++; 46 | // } 47 | 48 | // int count = 0, modus = 0; 49 | // for(const auto& pair : mapping) { 50 | // if(pair.second >= count) { 51 | // modus = pair.first; 52 | // count = pair.second; 53 | // } 54 | // } 55 | 56 | // cout << modus; 57 | 58 | return 0; 59 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/9/9D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N, M; 14 | cin >> N >> M; 15 | 16 | int arr[N][M]; 17 | for(int i = 0; i < N; i++) 18 | for(int j = 0; j < M; j++) 19 | cin >> arr[i][j]; 20 | 21 | for(int j = 0; j < M; j++) { 22 | for(int i = N - 1; i >= 0; i--) 23 | cout << arr[i][j] << " "; 24 | 25 | cout << endl; 26 | } 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Submission/9/9E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | int main() { 29 | boost; 30 | 31 | int N, M, P; 32 | cin >> N >> M >> P; 33 | int NM[N][M], MP[M][P], NP[N][P]; 34 | 35 | for(int i = 0; i < N; i++) { 36 | for(int j = 0; j < P; j++) { 37 | NP[i][j] = 0; 38 | } 39 | } 40 | 41 | for(int i = 0; i < N; i++) { 42 | for(int j = 0; j < M; j++) { 43 | cin >> NM[i][j]; 44 | } 45 | } 46 | 47 | for(int i = 0; i < M; i++) { 48 | for(int j = 0; j < P; j++) { 49 | cin >> MP[i][j]; 50 | for(int k = 0; k < N; k++) { 51 | NP[k][j] += NM[k][i] * MP[i][j]; 52 | } 53 | } 54 | } 55 | 56 | for(int i = 0; i < N; i++) { 57 | for(int j = 0; j < P; j++) { 58 | cout << NP[i][j] << " "; 59 | } 60 | 61 | cout << endl; 62 | } 63 | 64 | return 0; 65 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/10_PassByReference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | using namespace std; 20 | 21 | #define ll long long 22 | #define ull unsigned long long 23 | #define bug(a) cout << a 24 | #define bugs(a) cout << a << ' ' 25 | #define debug(a) cout << a << endl 26 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 27 | 28 | void swapNum(int &a, int &b) { // Jika parameter tidak menggunakan adress, nilai dari x dan y tidak akan bertukar. 29 | int temp = a; 30 | a = b; 31 | b = temp; 32 | } 33 | 34 | int main() { 35 | boost; 36 | 37 | int x = 15, y = 10; 38 | swapNum(x, y); 39 | cout << x << " " << y; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_Cstring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | // // Strcpy -> Mengcopy seluruh isi string ke string lainnya 6 | // char source[] = "Hello, world!"; 7 | // char destination[20]; 8 | // strcpy(destination, source); 9 | 10 | // // Strncpy -> Mencopy string sampai batas n 11 | // char source[] = "Hello, world!"; 12 | // char destination[10]; 13 | // strncpy(destination, source, 5); 14 | // destination[5] = '\0'; // Manually add null-terminator 15 | // printf("%s", destination); // Hanya akan menampilkan hello 16 | 17 | // Strstr -> mencari alamat dari sebuah substring 18 | char text[] = "Hello, world!"; 19 | char substring[] = "world"; 20 | char *result = strstr(text, substring); 21 | if (result != NULL) { 22 | printf("Substring found at index: %ld\n", result - text); 23 | } else { 24 | printf("Substring not found.\n"); 25 | } 26 | 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_Erase_and_substr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | string s = "Pak opim berternak"; 7 | string substring1 = s.substr(0, 6); // Pak op 8 | string substring2 = s.substr(2, 3); // k o 9 | 10 | s.erase(1, 3); // Menghapus dari index 1 sebanyak 3 karakter 11 | 12 | cout << substring1 << endl; 13 | cout << substring2 << endl; 14 | cout << s; // Popim berternak 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_Insert.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | string s = "Pak Dengklek berternak"; 7 | string t = "dan Bu "; 8 | s.insert(4, t); // Memasukan string / char t ke index 4 dan seterusnya 9 | cout << s; // Pak dan Bu Dengklek berternak 10 | 11 | return 0; 12 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_Memset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | char s[50]; 7 | int arr[50]; 8 | int testing[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , 10}; 9 | 10 | int main() { 11 | memset(s, 'x', sizeof(s)); // Akan membuat setiap index dalam array s menjadi 'x' 12 | memset(arr, -1, sizeof(arr)); // Akan membuat setiap index dalam array menjadi -1 13 | // cout << s << endl << arr[0] << endl << arr[1]; 14 | memset(testing, -1, 12); // 12 adalah 3 byte, maka 3 angka pertama (index 0, 1, 2) akan diubah menjadi -1 15 | 16 | for(auto &v : testing) { 17 | cout << v << " "; 18 | } 19 | 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_OperasiChar.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grantgabriel/Competitive-Programming/684d5e563a2cf45c6697c305ac89c700c017c012/Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_OperasiChar.cpp -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/11_String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | string s = "Pak denny berternak"; 7 | string t1 = "denny"; 8 | string t2 = "pak"; 9 | string t3 = "erna"; 10 | 11 | // Find -> turunan fungsi dari string untuk mencari substring 12 | cout << s.find(t1) << endl; // Index ke 4 13 | cout << s.find(t2) << endl; // Garbage karena tidak ditemukan 14 | cout << s.find(t3) << endl; // Index ke 14 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/12_Rekursi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int jdd(int x) { 30 | if (x == 0) { 31 | return 0; 32 | } else { 33 | return jdd(x / 100) + (x % 100); 34 | } 35 | } 36 | 37 | int main() { 38 | boost; 39 | 40 | cout << jdd(19823); 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/13_FibonacciRecursive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int fib(int x) { 30 | if(x == 0) return 0; 31 | else if(x == 1) return 1; 32 | else return fib(x - 1) + fib(x - 2); 33 | } 34 | 35 | int main() { 36 | boost; 37 | 38 | cout << fib(6); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/13_PermutasiPass.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | void batang(int x) { 30 | if (x == 0) { 31 | printf("daun\n"); 32 | } else { 33 | batang(x - 1); 34 | batang(x - 1); 35 | } 36 | } 37 | 38 | int main() { 39 | boost; 40 | 41 | batang(3); 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/2_Struct.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | struct titik { 11 | int x; 12 | int y; 13 | }; 14 | 15 | int main() { 16 | boost; 17 | 18 | vector koordinat; 19 | 20 | for(int i = 0; i < 5; i++) { 21 | titik t; 22 | int tempY, tempX; 23 | cin >> tempX >> tempY; 24 | t.x = tempX; 25 | t.y = tempY; 26 | koordinat.push_back(t); 27 | } 28 | 29 | for(int i = 0; i < 5; i++) { 30 | cout << "(" << koordinat[i].x << " " << koordinat[i].y << ")"<< endl; 31 | } 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/3_Printf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | bool a = true, b = false, c = true, d = true; 5 | printf("%d %d %d %d", (a && !b || c && d), ((a || !b) && c || !d), (a || b && !c && d), (a && !d || !c || a && b)); 6 | 7 | 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/3_Scanf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char c1, c2, c3; 5 | int bil; 6 | 7 | int main() { 8 | // Untuk memastikan agar tidak terjadi salah scan character (Coba input p q 5 r); 9 | scanf("%c %c\n", &c1, &c2); 10 | scanf("%d\n", &bil); 11 | scanf("%c", &c3); 12 | 13 | printf("c1 = '%c' c2 = '%c' bil = '%d' c3 = '%c'", c1, c2, bil, c3); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/3_String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | 7 | // // Cara reguler membaca 1 token dalam c; 8 | // char buff[1001]; 9 | // scanf("%s", buff); 10 | // std::string s = buff; 11 | // printf("s = '%s'\n", s.c_str()); 12 | 13 | // Cara agar membaca 1 baris dalam c (Mirip getline); 14 | char buff[1001]; 15 | scanf("%[^\n]\n", buff); 16 | std::string s = buff; 17 | printf("s = '%s'\n", s.c_str()); 18 | 19 | 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/3_XOR.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | 14 | // XOR -> jika true ^ true == false, false ^ false == false, true ^ falswe = true; 15 | bool a = true, b = false, c = false, d = false; 16 | 17 | if(a ^ b and c ^ d) { 18 | cout << "Saya ganteng"; 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/6_While.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int n = 100; 14 | int i = 0; 15 | while (n > 1) { 16 | i = i + 1; 17 | n = n - (n / 2); 18 | } 19 | printf("%d", i); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/7_Break.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N = 10, M = 5; 14 | 15 | 16 | /* Loop ini akan melakukan loop sampai 4 dan mencetak selesai pada akhirnya. 17 | 18 | 19 | */ 20 | for(int i = 1; i <= N; i++) { 21 | if(i == M) { 22 | break; 23 | } 24 | 25 | cout << i << endl; 26 | } 27 | 28 | cout << "selesai"; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/7_Continue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N = 10, M = 2; 14 | 15 | // Akan mencetak 1 3 5 7 9 selesai. Setiap kelipatan 2 akan dicontinue 16 | for(int i = 0; i < N; i += 1) { 17 | if(i % M == 0) continue; 18 | 19 | cout << i << endl; 20 | } 21 | 22 | cout << "selesai"; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/7_Nested_Loop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N = 5; // cin >> N; 14 | 15 | for(int i = N - 1; i >= 1; i--) { 16 | for(int j = 1; j <= i; j++) { 17 | cout << " "; 18 | } 19 | 20 | for(int k = 1; k <= N - i; k+=1) { 21 | cout << "*"; 22 | } 23 | 24 | cout << endl; 25 | } 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/7_Prime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N; cin >> N; 14 | 15 | for(int i = 1; i <= N - 1) 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/9_ArrayStruct.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | struct dataAneh { 11 | int umur = 19; 12 | string nama = "Grant"; 13 | bool ganteng = true; 14 | }; 15 | 16 | int main() { 17 | boost; 18 | 19 | dataAneh data[4]; 20 | 21 | data[1].umur = 20; 22 | data[1].nama = "Kontolodon"; 23 | data[1].ganteng = false; 24 | 25 | data[2].nama = "Ganteng"; 26 | data[2].ganteng = false; 27 | 28 | data[3].umur = 22; 29 | 30 | for(int i = 0; i < 4; i++) { 31 | cout << data[i].nama << " " << data[i].umur << " "; 32 | string ketampanan = data[i].ganteng ? "GANTENG" : "JELEK"; 33 | cout << ketampanan << endl; 34 | } 35 | 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/9_Cokelat_Bebek.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define ll long long 3 | #define ull unsigned long long 4 | #define bug(a) cout << a; 5 | #define bugs(a) cout << a << ' '; 6 | #define debug(a) cout << a << endl; 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | using namespace std; 9 | 10 | int main() { 11 | boost; 12 | 13 | int N; cin >> N; 14 | 15 | int kandang[N][N]; 16 | 17 | for(int i = 0; i < N; i+=1) { 18 | for(int j = 0; j < N; j+=1) 19 | cin >> kandang[i][j]; 20 | } 21 | 22 | for(int i = 0; i < N; i+=1) { 23 | for(int j = 0; j < N; j+=1) { 24 | int temp; cin >> temp; 25 | kandang[i][j] += temp; 26 | } 27 | } 28 | 29 | for(int i = 0; i < N; i+=1) { 30 | for(int j = 0; j < N; j+=1) 31 | cout << kandang[i][j] << " "; 32 | 33 | cout << endl; 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Dasar/Testing/9_Ujian_Harian.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define ll long long 4 | #define ull unsigned long long 5 | #define bug(a) cout << a 6 | #define bugs(a) cout << a << ' ' 7 | #define debug(a) cout << a << endl 8 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 9 | using namespace std; 10 | 11 | int main() { 12 | boost; 13 | 14 | ll int N, jumlah = 0; cin >> N; 15 | vector V(N); 16 | 17 | for(auto &v : V) { 18 | cin >> v; 19 | jumlah += v; 20 | } 21 | 22 | ll count = 0; 23 | for(int v : V) { 24 | if(v * N >= jumlah) count++; // Trik menghindari pembagian, tidak perlu cari rataan 25 | } 26 | 27 | cout << count; 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/1. Perkenalan Pemrograman Kompetitif/Submission/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 8 | #define debug(a) cout << a << endl 9 | vector ans; 10 | 11 | bool desc(int a, int b) { 12 | return a > b; 13 | } 14 | 15 | void run_cases() { 16 | int N, M; cin >> N >> M; string target; cin >> target; 17 | vector grade1, grade2, grade3; 18 | int TA, TB, TC; 19 | 20 | for(int i = 0; i < N ; i++) { 21 | string temp; cin >> temp; 22 | int a, b, c; 23 | cin >> a >> b >> c; 24 | if(temp == target) { 25 | TA = a; TB = b; TC = c; 26 | } 27 | grade1.emplace_back(a); 28 | grade2.emplace_back(b); 29 | grade3.emplace_back(c); 30 | } 31 | 32 | map map3; 33 | for(int i = 0 ; i < N; i++) { 34 | map3[grade3[i]]++; 35 | } 36 | 37 | sort(grade3.begin(), grade3.end(), desc); 38 | grade3.erase(unique(grade3.begin(), grade3.end()), grade3.end()); 39 | 40 | bool kena = false; 41 | for(int i = 0; i < grade3.size(); i++) { 42 | // cout << "Testing grade3 #" << i << " " << grade3[i] << ' ' << map3[grade3[i]] << endl; 43 | if(grade3[i] == TC) kena = true; 44 | 45 | 46 | if(grade3[i] == TC and M >= map3[grade3[i]]) { 47 | ans.push_back("YA"); return; 48 | } else if(M <= 0) { 49 | ans.push_back("TIDAK"); return; 50 | } else if(!kena){ 51 | M -= map3[grade3[i]]; 52 | // cout << "M grade3 #" << i << " " << M << endl; 53 | } 54 | 55 | if(kena) break; 56 | } 57 | 58 | kena = false; 59 | map map2; 60 | for(int i = 0 ; i < N; i++) { 61 | map2[grade2[i]]++; 62 | } 63 | 64 | sort(grade2.begin(), grade2.end(), desc); 65 | grade2.erase(unique(grade2.begin(), grade2.end()), grade2.end()); 66 | 67 | for(int i = 0; i < grade2.size(); i++) { 68 | // cout << "Testing grade2 #" << i << " " << grade2[i] << ' ' << map2[grade2[i]] << endl; 69 | if(grade2[i] == TB) kena = true; 70 | 71 | if(grade2[i] == TB and M >= map2[grade2[i]]) { 72 | ans.push_back("YA"); return; 73 | } else if(M <= 0) { 74 | ans.push_back("TIDAK"); return; 75 | } else if(!kena) { 76 | M -= map2[grade2[i]]; 77 | // cout << "M grade2 #" << i << " " << M << endl; 78 | } 79 | 80 | if(kena) break; 81 | } 82 | 83 | kena = false; 84 | map map1; 85 | for(int i = 0 ; i < N; i++) { 86 | map1[grade1[i]]++; 87 | } 88 | 89 | sort(grade1.begin(), grade1.end(), desc); 90 | grade1.erase(unique(grade1.begin(), grade1.end()), grade1.end()); 91 | 92 | for(int i = 0; i < grade1.size(); i++) { 93 | // cout << "Testing grade1 #" << i << " " << grade1[i] << ' ' << map1[grade1[i]] << endl; 94 | if(grade1[i] == TA) kena = true; 95 | 96 | if(grade1[i] == TA and M >= map1[grade1[i]]) { 97 | ans.push_back("YA"); return; 98 | } else if(M <= 0) { 99 | ans.push_back("TIDAK"); return; 100 | } else { 101 | M -= map1[grade1[i]]; 102 | // cout << "M grade2 #" << i << " " << M << endl; 103 | } 104 | 105 | if(kena) ans.push_back("TIDAK"); 106 | } 107 | 108 | } 109 | 110 | int main() { 111 | boost; 112 | 113 | int T, i = 1; cin >> T; 114 | while(T--) { 115 | // cout << "CASES #" << i << endl; 116 | run_cases(); i++; 117 | } 118 | 119 | for(const auto &r : ans) { 120 | cout << r << endl; 121 | } 122 | 123 | return 0; 124 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/1. Perkenalan Pemrograman Kompetitif/Submission/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define bug(a) cout << a 5 | #define bugs(a) cout << a << ' ' 6 | #define debug(a) cout << a << endl 7 | 8 | int satuBaris[8], akhirBaris[8]; 9 | int R, C, lastRow; 10 | vector row; 11 | string full = "", emp = ""; 12 | 13 | void isiAkhir() { 14 | for(int i = 0; i < 8; i++) { 15 | akhirBaris[i] = R; 16 | } 17 | } 18 | 19 | bool adaLayakRuntuh() { 20 | for(auto &r : row) { 21 | if(r == full) { 22 | return true; 23 | } 24 | } 25 | return false; 26 | } 27 | 28 | void hitungAtas() { 29 | // memset(satuBaris, 0, sizeof(satuBaris)); 30 | for(int i = 0; i < C; i++) { 31 | for(int j = 0; j < lastRow; j++) { 32 | if(row[j][i] == '1') { 33 | satuBaris[i] += 1; 34 | row[j][i] = '0'; 35 | } 36 | } 37 | } 38 | } 39 | 40 | void hitungBawah() { 41 | // memset(akhirBaris, R, sizeof(akhirBaris)); 42 | isiAkhir(); 43 | for(int i = 0; i < C; i++) { 44 | for(int j = R - 1; j >= lastRow; j--) { 45 | if(row[j][i] == '1') { 46 | akhirBaris[i] = j; 47 | } 48 | } 49 | } 50 | } 51 | 52 | void stackBawah() { 53 | for(int i = 0; i < C; i++) { 54 | for(int j = akhirBaris[i] - 1; (satuBaris[i] > 0) and (j >= 0); j--) { // Masalah pada j != 0 atau j >= 0 55 | row[j][i] = '1'; 56 | satuBaris[i]--; 57 | } 58 | } 59 | } 60 | 61 | void peruntuhan() { 62 | lastRow = 0; int ite = 0; 63 | for(auto &r : row) { 64 | if(r == full) { 65 | r = emp; 66 | lastRow = ite; 67 | } 68 | ite++; 69 | } 70 | 71 | hitungAtas(); 72 | hitungBawah(); 73 | stackBawah(); 74 | } 75 | 76 | int main() { 77 | cin >> R >> C; 78 | memset(satuBaris, 0, sizeof(satuBaris)); 79 | 80 | for(int i = 0; i < C; i++) { 81 | full += "1"; 82 | emp += "0"; 83 | } 84 | 85 | for(int i = 0; i < R; i++) { 86 | string temp; cin >> temp; 87 | row.push_back(temp); 88 | } 89 | 90 | while(adaLayakRuntuh()) { 91 | peruntuhan(); 92 | // cout << "Hasil : " << endl; 93 | // for(auto &r : row) 94 | // cout << r << endl; 95 | 96 | // cout << endl << endl; 97 | } 98 | 99 | for(auto &r : row) 100 | cout << r << endl; 101 | 102 | return 0; 103 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/1. Perkenalan Pemrograman Kompetitif/Submission/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #define bug(a) cout << a 9 | #define bugs(a) cout << a << ' ' 10 | #define debug(a) cout << a << endl 11 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 12 | 13 | int main() { 14 | boost; 15 | 16 | string ask, s; cin >> ask; 17 | int N; cin >> N; 18 | vector words(N); 19 | for(auto &w : words) { 20 | cin >> w; 21 | } 22 | 23 | if(ask == "*") { 24 | for(auto &w : words) { 25 | cout << w << endl; 26 | } 27 | } else { 28 | for(int x = 0; x < N; x++) { 29 | string s = words[x]; 30 | if(s.length() < ask.length() - 1) continue; 31 | 32 | bool cocok = true; 33 | int asterisk = ask.find('*'), indexAwal = 0; 34 | for(int i = 0; i < asterisk and cocok; i++) { 35 | if(ask[i] != s[indexAwal++]) { 36 | cocok = false; 37 | break; 38 | } 39 | } 40 | 41 | int indexAkhir = s.length() - 1; 42 | for(int i = ask.length() - 1; ask[i] != '*' and cocok; i--) { 43 | if(ask[i] != s[indexAkhir--]) { 44 | cocok = false; 45 | } 46 | } 47 | 48 | if(cocok) cout << s << endl; 49 | } 50 | } 51 | 52 | 53 | 54 | // else if(ask[ask.length() - 1] == '*') { 55 | // string target = ask.substr(0, ask.length() - 1 ); 56 | // for(auto &w : words) { 57 | // bool found = true; 58 | // for(int i = 0; i < ask.length() - 1; i++) { 59 | // if(w[i] != ask[i]) { 60 | // found = false; 61 | // } 62 | // } 63 | 64 | // if(found) cout << w << endl; 65 | // } 66 | // } else if(ask[0] == '*') { 67 | // string target = ask.substr(1, ask.length() - 1); 68 | // for(auto &w : words) { 69 | // if(w.find(target) < w.length() and w.find(target) > 0) { 70 | // cout << w << endl; 71 | // } 72 | // } 73 | // } else { 74 | // int asteriskIndex; 75 | // for(int i = 0; i < ask.length(); i++) { 76 | // if(ask[i] = '*') asteriskIndex = i; 77 | // } 78 | 79 | // string A, B; 80 | // A = ask.substr(0, asteriskIndex - 1); debug(A); 81 | // B = ask.substr(asteriskIndex + 1, ask.length() - 1); debug(B); 82 | 83 | // for(auto &w : words) { 84 | // if((ask.find(A) < ask.length() and ask.find(A) > 0) and (ask.find(B) < ask.length() and ask.find(B) > 0)) { 85 | // cout << w << endl; 86 | // } 87 | // } 88 | // } 89 | 90 | return 0; 91 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/1. Perkenalan Pemrograman Kompetitif/Submission/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | 8 | string A, B; cin >> A >> B; 9 | 10 | int count = 0, j = 0; 11 | 12 | for(int i = 0; i < B.length(); i++) { 13 | if(A[j] == B[i]) j++; 14 | else { 15 | count ++; j++; i--; 16 | } 17 | } 18 | 19 | if(A.length() - B.length() != 1) cout << "Wah, tidak bisa :("; 20 | else if(count == 1) cout << "Tentu saja bisa!"; 21 | else if(count == 0 and A.length() - B.length() == 1) cout << "Tentu saja bisa!"; 22 | else cout << "Wah, tidak bisa :("; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/1. Perkenalan Pemrograman Kompetitif/Testing/lampu_dan_tombol.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define ll long long 4 | using namespace std; 5 | 6 | int main() { 7 | /* Best solution */ 8 | ll N; cin >> N; 9 | ll s = round(sqrt(N)); 10 | if(s * s != N) { 11 | cout << "lampu mati" << endl; 12 | } else { 13 | cout << "lampu menyala" << endl; 14 | } 15 | 16 | return 0; 17 | 18 | /* Solusi efektif tapi kurang */ 19 | 20 | // ll N; cin >> N; ll num = N; 21 | 22 | // int divisorCount = 1; 23 | // for(ll i = 2; i * i <= num; i++) { 24 | // int factorCount = 0; 25 | // while(num % i == 0) { 26 | // factorCount+=1; 27 | // num /= i; 28 | // } 29 | 30 | // divisorCount *= (1 + factorCount); 31 | // } 32 | 33 | // if(num > 1) { 34 | // divisorCount *= 2; 35 | // } 36 | 37 | // if(divisorCount % 2 == 0) { 38 | // cout << "lampu mati" << endl; 39 | // return 0; 40 | // } 41 | 42 | // cout << "lampu menyala" << endl; 43 | // return 0; 44 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/2. Matematika Diskret Dasar/Submission/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | ll gcd(ll a, ll b) { 30 | while (b != 0) { 31 | ll temp = b; 32 | b = a % b; 33 | a = temp; 34 | } 35 | return a; 36 | } 37 | 38 | 39 | int main() { 40 | boost; 41 | 42 | ll A, B, C, D; cin >> A >> B >> C >> D; 43 | ll X = (A*D) + (B*C); 44 | ll Y = B * D; 45 | ll gcdRes = gcd(X, Y); 46 | cout << X / gcdRes << " " << Y / gcdRes; 47 | 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/2. Matematika Diskret Dasar/Submission/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | #define ll long long 8 | #define ull unsigned long long 9 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 10 | vector primeList; 11 | 12 | // void sieveOfEratosthenes(ll N) { 13 | // bool eleminated[N + 1]; ll j; 14 | 15 | // for(int i = 2; i < N; i++) { 16 | // if(!eleminated[i]) { 17 | // primeList.push_back(i); 18 | // j = i * i; 19 | 20 | // while(j <= N) { 21 | // eleminated[j] = true; 22 | // j += i; 23 | // } 24 | // } 25 | // } 26 | // } 27 | 28 | bool checkPrime(int x) { 29 | if(x <= 1) { 30 | return false; 31 | } else { 32 | int i = 2; 33 | while(i * i <= x) { 34 | if(x % i == 0) return false; 35 | i++; 36 | } 37 | 38 | return true; 39 | } 40 | } 41 | 42 | void isiPrimeList() { 43 | for(int i = 0; i < 1000000; i++) { 44 | if(checkPrime(i)) { 45 | primeList.push_back(i); 46 | } 47 | } 48 | } 49 | 50 | void run_cases() { 51 | ll N; cin >> N; 52 | cout << primeList[N - 1] << endl; 53 | } 54 | 55 | int main() { 56 | boost; 57 | isiPrimeList(); 58 | 59 | ll T; cin >> T; 60 | 61 | while(T--) { 62 | run_cases(); 63 | } 64 | 65 | return 0; 66 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/2. Matematika Diskret Dasar/Submission/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | #define bug(a) cout << a 9 | #define bugs(a) cout << a << ' ' 10 | #define debug(a) cout << a << endl 11 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 12 | 13 | int gcd(int a, int b) { 14 | if(b == 0) return a; 15 | 16 | return gcd(b, a % b); 17 | } 18 | 19 | int lcm(int a, int b) { 20 | return a * b / gcd(a, b); 21 | } 22 | 23 | int main() { 24 | boost; 25 | 26 | int N; cin >> N; 27 | int A[N]; 28 | for(int i = 0; i < N; i++) { 29 | cin >> A[i]; 30 | } 31 | 32 | int res = lcm(A[0], A[1]); 33 | 34 | for(int i = 2; i < N; i++) { 35 | res = lcm(res, A[i]); 36 | } 37 | 38 | cout << res; 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | 9 | int N, target; cin >> N >> target; 10 | int diff = INT_MAX, diffTemp = INT_MAX, temp, final = INT_MAX; 11 | 12 | while(N--) { 13 | cin >> temp; 14 | diffTemp = abs(target - temp); 15 | if(diff > diffTemp) { 16 | diff = diffTemp; 17 | final = temp; 18 | } else if(diff == diffTemp) { 19 | if(temp < final) 20 | final = temp; 21 | } 22 | } 23 | 24 | cout << final; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | #define ull unsigned long long 10 | #define debug(a) cout << a << endl 11 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 12 | vector> ans; bool ada = false; 13 | int N, M, K; int grid[150][150]; 14 | 15 | void countNeighbors(int x, int y) { 16 | ull total; 17 | total = grid[x][y + 1] * grid[x][y - 1] * grid[x + 1][y] * grid[x - 1][y]; 18 | 19 | if(total == K) { 20 | ans.push_back(make_pair(y, x)); ada = true; 21 | } 22 | } 23 | 24 | void findAnswer() { 25 | if(!ada) { 26 | cout << "0 0"; return; 27 | } else if(ans.size() < 2) { 28 | cout << ans[0].first << " " << ans[0].second; 29 | } 30 | 31 | int temp; 32 | sort(ans.begin(), ans.end()); 33 | 34 | if(ans[0].first == ans[1].first) { 35 | temp = min(ans[0].second, ans[1].second); 36 | cout << temp << " " << ans[0].first; 37 | } else { 38 | cout << ans[0].second << " " << ans[0].first; 39 | } 40 | } 41 | 42 | int main() { 43 | boost; 44 | cin >> N >> M >> K; 45 | 46 | for(int i = 0; i < 150; i++) { 47 | for(int j = 0; j < 150; j++) { 48 | grid[i][j] = 1; 49 | } 50 | } 51 | 52 | int temp; 53 | for(int i = 1; i <= N; i++) { 54 | for(int j = 1; j <= M; j++) { 55 | cin >> temp; 56 | grid[i][j] = temp; 57 | } 58 | } 59 | 60 | for(int x = 1; x <= N; x++) { 61 | for(int y = 1; y <= M; y++) { 62 | countNeighbors(x, y); 63 | } 64 | } 65 | 66 | findAnswer(); 67 | 68 | return 0; 69 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | int N, Q; cin >> N >> Q; 33 | map daftar; 34 | 35 | string nama, noTelp; 36 | while(N--) { 37 | cin >> nama >> noTelp; 38 | daftar[nama] = noTelp; 39 | 40 | } 41 | 42 | string dicari; 43 | while(Q--) { 44 | cin >> dicari; 45 | if(daftar[dicari] == "") { 46 | cout << "NIHIL" << endl; 47 | } else { 48 | cout << daftar[dicari] << endl; 49 | } 50 | } 51 | 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | using namespace std; 6 | #define ull unsigned long long 7 | int N, Q; 8 | vector bebeks; 9 | 10 | int binarySearch(ull target) { 11 | int kiri = 0; 12 | int kanan = N - 1; 13 | int tengah = kiri + (kanan - kiri) / 2; 14 | 15 | while(kiri <= kanan) { 16 | tengah = kiri + (kanan - kiri) / 2; 17 | if(bebeks[tengah] <= target) { 18 | kiri = tengah + 1; 19 | } 20 | 21 | else kanan = tengah - 1; 22 | } 23 | 24 | return kiri; 25 | } 26 | 27 | int main() { 28 | ull temp; 29 | 30 | cin >> N; int tc = N; 31 | while(tc--) { 32 | cin >> temp; 33 | bebeks.push_back(temp); 34 | } 35 | 36 | cin >> Q; 37 | ull x, y; 38 | while(Q--) { 39 | cin >> x >> y; 40 | // cerr << binarySearch(y) << " " << binarySearch(x); 41 | cout << binarySearch(y) - binarySearch(x) << endl; 42 | } 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | int N; cin >> N; 33 | vector tamu(N), jawaban; 34 | 35 | for(auto &r : tamu) { 36 | cin >> r; 37 | } 38 | 39 | for(int i = 1; i <= 10; i++) { 40 | vector temp; 41 | 42 | for(auto &x : tamu) { 43 | if(x.length() == i) { 44 | temp.push_back(x); 45 | } 46 | } 47 | 48 | sort(temp.begin(), temp.end()); 49 | for(auto &x : temp) { 50 | jawaban.push_back(x); 51 | } 52 | } 53 | 54 | for(const auto& x : jawaban) 55 | cout << x << endl; 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | vector dataBebek; 29 | 30 | void run_cases() { 31 | string temp; cin >> temp; 32 | dataBebek.push_back(temp); 33 | sort(dataBebek.begin(), dataBebek.end()); 34 | 35 | int counter = 0; 36 | for(const auto &x : dataBebek) { 37 | if(x == temp) { 38 | cout << counter + 1 << endl; 39 | } else { 40 | counter++; 41 | } 42 | } 43 | } 44 | 45 | int main() { 46 | boost; 47 | 48 | int N; cin >> N; 49 | 50 | while(N--) { 51 | run_cases(); 52 | cout << flush; 53 | } 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/G.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int N; cin >> N; 6 | 7 | vector list(N); 8 | 9 | for(auto &r : list) { 10 | cin >> r; 11 | } 12 | 13 | sort(list.begin(), list.end()); 14 | 15 | if(N % 2 == 0) { 16 | cout << setprecision(1) << fixed << ((list[N / 2 - 1] + list[(N / 2)]) / 2.0); 17 | } else { 18 | cout << setprecision(1) << fixed << list[N / 2]; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | // 0 1 2 3 4 -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/H.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | struct Rice { 5 | int weight; 6 | int price; 7 | }; 8 | 9 | bool comp(Rice a, Rice b) { 10 | return (double)a.price / a.weight > (double)b.price / b.weight; 11 | } 12 | 13 | int main() { 14 | int N, X; cin >> N >> X; 15 | 16 | Rice rice[N]; 17 | 18 | for(int i = 0; i < N; i++) { 19 | cin >> rice[i].weight; 20 | } 21 | 22 | for(int i = 0; i < N; i++) { 23 | cin >> rice[i].price; 24 | } 25 | 26 | sort(rice, rice + N, comp); 27 | 28 | for(int i = 0; i < N; i++) { 29 | cerr << rice[i].weight << " " << rice[i].price << endl; 30 | } 31 | 32 | double total = 0.0; 33 | 34 | for(int i = 0; i < N and X > 0; i++) { 35 | int buy = min(X, rice[i].weight); 36 | total += (double)rice[i].price / rice[i].weight * buy; 37 | X -= buy; 38 | } 39 | 40 | cout << setprecision(5) << fixed << total << endl; 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Submission/I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int N, K; cin >> N >> K; 6 | 7 | vector bebeks(N); 8 | 9 | for(auto &bebek : bebeks) { 10 | cin >> bebek; 11 | } 12 | 13 | sort(bebeks.begin(), bebeks.end()); 14 | 15 | cout << bebeks[K - 1]; 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Testing/binary_search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int binarySearch(int arr[], int target, int size) { 5 | int kiri = 0; 6 | int kanan = size - 1; 7 | int tengah = kiri + (kanan - kiri) / 2; 8 | 9 | while(kanan >= kiri) { 10 | tengah = kiri + (kanan - kiri) / 2; 11 | 12 | if(arr[tengah] == target) { 13 | return tengah; 14 | } else if(target > arr[tengah]) { 15 | kiri = tengah + 1; 16 | } else { 17 | kanan = tengah - 1; 18 | } 19 | } 20 | 21 | return -1; 22 | } 23 | 24 | 25 | int main() { 26 | 27 | int arr[] = {1, 2, 3, 4, 5, 6, 7}; 28 | int size = sizeof(arr)/sizeof(arr[0]); 29 | int hasil = binarySearch(arr, 7, size); 30 | 31 | cout << hasil << endl; 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Testing/counting_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | void countingSort(int arr[], int size) { 9 | int fTable[100000]; 10 | memset(fTable, 0, sizeof(fTable)); 11 | for(int i = 0; i < size; i++) { 12 | int x = arr[i]; 13 | fTable[x] += 1; 14 | } 15 | 16 | int index = 0; 17 | for(int i = 0; i < 100000; i++) { 18 | for(int j = 0; j < fTable[i]; j++) { 19 | arr[index] = i; 20 | index += 1; 21 | } 22 | } 23 | } 24 | 25 | int main() { 26 | int arr[] = {9, 8, 7, 6, 5, 4, 4, 4, 3, 3, 2, 2, 2, 2, 2, 1}; 27 | int size = sizeof(arr)/sizeof(int); 28 | 29 | countingSort(arr, size); 30 | 31 | for(int i : arr) { 32 | cout << i << " "; 33 | } 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Testing/insertion_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 6 | 7 | void insertionSort(int arr[], int size) { 8 | for(int i = 0; i <= size; i++) { 9 | int pos = i; 10 | while(pos >= 1 and (arr[pos] < arr[pos - 1])) { 11 | swap(arr[pos], arr[pos - 1]); 12 | pos -= 1; 13 | } 14 | } 15 | } 16 | 17 | int main() { 18 | boost; 19 | 20 | int arr[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; 21 | int size = sizeof(arr)/sizeof(int); 22 | 23 | insertionSort(arr, size); 24 | 25 | for(auto x : arr) { 26 | cout << x << " "; 27 | } 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/3. Pencarian dan Pengurutan/Testing/selection_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | #define ull unsigned long long 6 | #define bug(a) cout << a 7 | #define bugs(a) cout << a << ' ' 8 | #define debug(a) cout << a << endl 9 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 10 | 11 | void selectionSort(int arr[], int size) { 12 | for(int i = 0; i < size; i++) { 13 | int leastIndex = i; 14 | for(int j = i + 1; j < size; j++) { 15 | if (arr[j] < arr[leastIndex]) { 16 | leastIndex = j; 17 | } 18 | } 19 | 20 | swap(arr[i], arr[leastIndex]); 21 | } 22 | } 23 | 24 | int main() { 25 | boost; 26 | 27 | int arr[] = {1, 4, 7, 2, 5, 7, 8, 2, 0}; 28 | int size = sizeof(arr)/sizeof(int); 29 | 30 | selectionSort(arr, size); 31 | 32 | for(int x : arr) { 33 | cout << x << " "; 34 | } 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/4. Brute Force/Submission/A.cpp: -------------------------------------------------------------------------------- 1 | // Solved By : Grant Gabriel Tambunan 2 | // Connect With Me : https://www.linkedin.com/in/grantgabrieltambunan/ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | #define all(a) a.begin(), a.end() 11 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 12 | 13 | string identik(const vector> &m1, const vector> &m2, int N) { 14 | for(int i = 0; i < N; i++) 15 | for(int j = 0; j < N; j++) 16 | if(m1[i][j] != m2[i][j]) 17 | return ""; 18 | 19 | return "identik"; 20 | } 21 | 22 | string vertikal(const vector> &m1, const vector> &m2, int N) { 23 | vector> temp = m2; 24 | 25 | for(auto& x : temp) { 26 | reverse(x.begin(), x.end()); 27 | } 28 | 29 | for(int i = 0; i < N; i++) 30 | for(int j = 0; j < N; j++) 31 | if(m1[i][j] != temp[i][j]) 32 | return ""; 33 | 34 | return "vertikal"; 35 | } 36 | 37 | string horizontal(const vector> &m1, const vector> &m2, int N) { 38 | vector> temp = m2; 39 | reverse(all(temp)); 40 | 41 | for(int i = 0; i < N; i++) 42 | for(int j = 0; j < N; j++) 43 | if(m1[i][j] != temp[i][j]) 44 | return ""; 45 | 46 | return "horisontal"; 47 | } 48 | 49 | string diagonalkananbawah(const vector> &m1, const vector> &m2, int N) { 50 | for(int i = 0; i < N; i++) 51 | for(int j = 0; j < N; j++) 52 | if(m1[i][j] != m2[j][i]) 53 | return ""; 54 | 55 | return "diagonal kanan bawah"; 56 | } 57 | 58 | string diagonalkiribawah(const vector> &m1, const vector> &m2, int N) { 59 | vector> temp; 60 | 61 | for(int i = N - 1; i >= 0; i--) { 62 | vector row; 63 | for(int j = N - 1; j >= 0; j--) 64 | row.emplace_back(m2[i][j]); 65 | 66 | temp.emplace_back(row); 67 | } 68 | 69 | for(int i = 0; i < N; i++) 70 | for(int j = 0; j < N; j++) 71 | if(m1[i][j] != temp[j][i]) 72 | return ""; 73 | 74 | return "diagonal kiri bawah"; 75 | } 76 | 77 | int main() { 78 | boost; 79 | 80 | int N; 81 | cin >> N >> N; 82 | 83 | vector> m1(N, vector(N)), m2(N, vector(N)); 84 | for(int i = 0; i < N; i++) { 85 | for(int j = 0; j < N; j++) { 86 | cin >> m1[i][j]; 87 | } 88 | } 89 | 90 | cin >> N >> N; 91 | for(int i = 0; i < N; i++) { 92 | for(int j = 0; j < N; j++) { 93 | cin >> m2[i][j]; 94 | } 95 | } 96 | 97 | 98 | if(identik(m1, m2, N) == "identik") 99 | cout << "identik" << endl; 100 | else if(vertikal(m1, m2, N) == "vertikal") 101 | cout << "vertikal" << endl; 102 | else if(horizontal(m1, m2, N) == "horisontal") 103 | cout << "horisontal" << endl; 104 | else if(diagonalkananbawah(m1, m2, N) == "diagonal kanan bawah") 105 | cout << "diagonal kanan bawah" << endl; 106 | else if(diagonalkiribawah(m1, m2, N) == "diagonal kiri bawah") 107 | cout << "diagonal kiri bawah" << endl; 108 | else 109 | cout << "tidak identik" << endl; 110 | 111 | return 0; 112 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/4. Brute Force/Submission/B.cpp: -------------------------------------------------------------------------------- 1 | // Solved By : Grant Gabriel Tambunan 2 | // Connect With Me : https://www.linkedin.com/in/grantgabrieltambunan/ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | using namespace std; 24 | 25 | #define ll long long 26 | #define ull unsigned long long 27 | #define all(a) a.begin(), a.end() 28 | #define debug(a) cout << a << endl 29 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 30 | 31 | int main() { 32 | boost; 33 | 34 | 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Learning Progress/TLX Toki/Pemrograman Kompetitif Dasar/4. Brute Force/Testing/subset_sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; 5 | int N = 20; 6 | bool subset_sum(int i, int sum) { 7 | if(i > N) { 8 | if(sum = K) { 9 | return true; 10 | } else { 11 | return false; 12 | } 13 | } 14 | 15 | return subset_sum(i + 1, sum + arr[i]) or subset_sum(i + 1, sum); 16 | } 17 | 18 | int main() { 19 | cout << ((subset_sum(0, 45)) ? "ADA" : "TIDAK ADA"); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚀 Competitive Programming 2 | 3 | ## Introduction 👋 4 | Hi! I'm Grant, an IT student @USU. This is my competitive programming journey. I'll document every competitive programming i do and learn, then built my portfolio based of it. This is different from my other Data Structure and Algorithm repository, because this repos only contain every competition i compete in and also materials im learning. 5 | 6 | ## Contact & Issues 📩 7 | Please contact me via gmail in my profile for any question, or feel free to open up an issues page and i'll happily check it. ^3^)/ ~ -------------------------------------------------------------------------------- /Template & Library/SimplifiedTemplateCP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define bug(a) cout << a 25 | #define bugs(a) cout << a << ' ' 26 | #define debug(a) cout << a << endl 27 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL) 28 | 29 | int main() { 30 | boost; 31 | 32 | 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Template & Library/TemplateCP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | #define ll long long 23 | #define ull unsigned long long 24 | #define pii pair 25 | #define pll pair 26 | #define vi vector 27 | #define vll vector 28 | #define mii map 29 | #define si set 30 | #define sc set 31 | 32 | #define fors(i,s,e) for(long long int i=s;i=s;i--) 36 | #define bug(a) cout << a 37 | #define bugs(a) cout << a << ' ' 38 | #define debug(a) cout << a << endl 39 | #define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 40 | #define pb push_back 41 | #define eb emplace_back 42 | #define sw swap 43 | 44 | template 45 | void print_v(vector &v) { 46 | cout << "{"; 47 | for (auto x : v) 48 | cout << x << ","; 49 | cout << "\b}"; 50 | } 51 | 52 | #define MOD 1000000007 53 | #define PI 3.1415926535897932384626433832795 54 | #define read(type) readInt() 55 | ll min(ll a,ll b) { if (ab) return a; return b; } 58 | ll max(ll a,ll b) { if (a>b) return a; return b; } 59 | ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); } 60 | ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } 61 | 62 | string to_upper(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a;} 63 | string to_lower(string a) {for (int i=0;i<(int)a.size();++i)if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a;} 64 | 65 | bool prime(ll a) {if (a==1) return 0;for (int i=2;i<=round(sqrt(a));++i)if (a%i==0) return 0; return 1; } 66 | 67 | void yes() {cout<<"YES\n";} 68 | void no() {cout<<"NO\n";} 69 | void cs(int n) {cout<<"Case #"<