complete 1764.cpp 10816.cpp 25793.kt

This commit is contained in:
2025-09-08 17:14:06 +09:00
parent f18ae8d149
commit 603f94f8d8
3 changed files with 133 additions and 0 deletions

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";
}

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 ;
}

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}"
})
}
}