complete 1764.cpp 10816.cpp 25793.kt

This commit is contained in:
yenru0 committed 2025-09-08 17:15:00 +09:00
1 parent f18ae8d149
commit 603f94f8d8
3 files changed
+133

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
#include <map>
#include <iostream>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main() {
fastio();
int n;
cin >> n;
map<int, int> 상근이카드;
int x;
for (auto i = 0; i < n; i++) {
cin >> x;
auto pos = 상근이카드.find(x);
if (pos == 상근이카드.end()) {
상근이카드[x] = 1;
} else {
pos->second++;
}
}
int m;
cin >> m;
for (auto i = 0; i < m; i++) {
cin >> x;
auto pos = 상근이카드.find(x);
if (pos == 상근이카드.end()) {
cout << "0 ";
} else {
cout << pos->second << " ";
}
}
cout << "\n";
}
+55
View File
@@ -0,0 +1,55 @@
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main() {
fastio();
int n, m;
cin >> n >> m;
auto 듣도못한사람 = new set<string>();
auto 보도못한사람 = new set<string>();
for (auto i = 0; i < n; i++) {
string name;
cin >> name;
듣도못한사람->insert(name);
}
for (auto j = 0; j < m; j++) {
string name;
cin >> name;
보도못한사람->insert(name);
}
auto 듣도보도못한사람 = new vector<string>();
set_intersection(
듣도못한사람->begin(), 듣도못한사람->end(),
보도못한사람->begin(), 보도못한사람->end(),
back_inserter(*듣도보도못한사람)
);
cout << 듣도보도못한사람->size() << "\n";
for (auto name: *듣도보도못한사람) {
cout << name << "\n";
}
delete 듣도못한사람;
delete 보도못한사람;
delete 듣도보도못한사람;
}
+36
View File
@@ -0,0 +1,36 @@
import kotlin.math.min
fun chocolatePyramidSum(r: Int, c: Int): Long {
val m = min(r, c).toLong()
return m * (4 * m * m - 6 * m * (r.toLong() + c.toLong()) + 12 * r.toLong() * c.toLong() - 1) / 3
}
fun chocolatePyramidDark(r: Int, c: Int): Long {
val m = min(r, c).toLong()
return m * (2 * m * m - 3 * m * (r.toLong() + c.toLong()) + 6 * r.toLong() * c.toLong() - 2) / 3
}
fun chocolatePyramid(r: Int, c: Int): Pair<Long, Long> {
// W(r, c) = (r * c) + (r-1) * (c-1) + D(r-1, c-1)
// D(r, c) = (r - 1) * c + r * (c-1) + W(r-1, c-1)
// therefore,
// W(r, c) = (r * c) + 2*(r-1)*(c-1) ...(until r-k or c-k is equal to 0)
// D(r, c) = (r - 1) * c + r * (c-1) + (r-2) * (c-1) + (r - 1) * (c-2)
//(r*c) + (r-1) * c + r * (c-1) + (r-1) * (c-1)
// S(r, c) = (2r-1)(2c-1) + S(r-1, c-1)
val s = chocolatePyramidSum(r, c)
val d = chocolatePyramidDark(r, c)
return s - d to d
}
fun main() = with(System.`in`.bufferedReader()) {
val t = this.readLine().toInt()
repeat(t) {
val (r, c) = this.readLine().split(" ").map { it.toInt() }
println(chocolatePyramid(r, c).let {
"${it.first} ${it.second}"
})
}
}