migrate small contest

This commit is contained in:
2026-05-04 14:59:37 +09:00
parent cac746a69c
commit d6777983a1
12 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
#include <iostream>
#include <vector>
using namespace std;
int max_customs_sold(const vector<int> &arr) {
int num500 = 0;
int num1000 = 0;
int num5000 = 0;
int cnt = 0;
for (int e: arr) {
if (e == 500) {
num500++;
cnt++;
} else if (e == 1000) {
if (num500 >= 1) {
num1000++;
num500--;
cnt++;
} else { break; }
} else {
if (num1000 >= 4 && num500 >= 1) {
num5000++;
num1000 -= 4;
num500--;
cnt++;
} else if (num1000 >= 3 && num500 >= 3) {
num5000++;
num1000 -= 3;
num500 -= 3;
cnt++;
} else if (num1000 >= 2 && num500 >= 5) {
num5000++;
num1000 -= 2;
num500 -= 5;
cnt++;
} else if (num1000 >= 1 && num500 >= 7) {
num5000++;
num1000 -= 1;
num500 -= 7;
cnt++;
} else if (num500 >= 9) {
num5000++;
num500 -= 9;
cnt++;
} else {
break;
}
}
}
return cnt;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin >> t;
for (int test_case = 1; test_case <= t; test_case++) {
int n;
cin >> n;
vector<int> v;
for (int j = 0; j < n; j++) {
int x;
cin >> x;
v.push_back(x);
}
cout << "Case #" << test_case << endl;
cout << max_customs_sold(v) << endl;
}
return 0;
}

View File

@@ -0,0 +1,37 @@
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
long long total_legal_minimum_length(int length, vector<int> pos) {
long long legal_length = pos[0];
for (auto i = 0; i < pos.size() - 1; i++) { legal_length += min(pos[i] + pos[i + 1], length - pos[i] + length - pos[i + 1]); }
legal_length += min(length - pos[pos.size() - 1], pos[pos.size() - 1]);
return legal_length;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
size_t t;
cin >> t;
for (auto test_case = 1; test_case <= t; test_case++) {
int n, l;
cin >> n >> l;
int tmp;
vector<int> p;
for (auto i = 0; i < n; i++) {
cin >> tmp;
p.push_back(tmp);
}
cout << "Case #" << test_case << endl;
cout << total_legal_minimum_length(l, p) << endl;
}
}

View File

@@ -0,0 +1,93 @@
#include <iostream>
using namespace std;
constexpr long long MOD = 1000000007;
int POW3[100001];
int get_count_decimal_012(const string &s) {
auto n = s.size();
if (n == 1) { if (s[0] == '1') { return 1; } else { return 2; } }
auto cnt = 0LL;
// f (1 until 10^(n-1))을 구하기
auto temp = 1LL;
POW3[0] = temp;
for (auto i = 1; i <= (n - 1); i++) {
temp *= 3;
temp %= MOD;
POW3[i] = temp;
}
temp += MOD - 1;
temp %= MOD;
cnt += temp;
cnt %= MOD;
// f(10^(n-1) to int(s)) 까지 구하기
if (s[0] == '0') {
// pass
} else if (s[0] == '1') {
// pass
} else if (s[0] == '2') {
long long tmpx = POW3[n - 1];
cnt += tmpx;
cnt %= MOD;
} else {
long long tmpx = POW3[n - 1];
tmpx *= 2;
cnt += tmpx;
cnt %= MOD;
return static_cast<int>(cnt);
}
bool flag = false;
for (int i = 1; i < n; i++) {
auto ch = s[i];
if (ch == '0') { continue; } else if (ch == '1') {
long long tmpx = POW3[n - i - 1];
cnt += tmpx;
cnt %= MOD;
} else if (ch == '2') {
long long tmpx = 2 * POW3[n - i - 1];
cnt += tmpx;
cnt %= MOD;
} else {
long long tmpx;
tmpx = POW3[n - i];
cnt += tmpx;
cnt %= MOD;
flag = true;
break;
}
}
if (!flag) {
cnt++;
cnt %= MOD;
}
return static_cast<int>(cnt);
}
int main() {
ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin >> t;
for (auto test_case = 1; test_case <= t; test_case++) {
string s;
cin >> s;
cout << "Case #" << test_case << endl;
cout << get_count_decimal_012(s) << endl;
}
}

View File

@@ -0,0 +1,42 @@
#include <iostream>
#include <vector>
using namespace std;
long long minimum_total_movement_length(
int n, int reds,
const vector<int> &pos_blue_houses, const vector<int> &pos_red_houses, const vector<int> &pos_blue_shops, const vector<int> &pos_red_shops
) {
long long cost = 0;
pos_red_houses
return cost;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for (auto test_case = 1; test_case <= t; test_case++) {
int n, reds;
cin >> n >> reds;
vector<int> pos_blue_houses(n - reds), pos_red_houses(reds), pos_blue_shops(n - reds - 1), pos_red_shops(reds + 1);
for (auto i = 0; i < n - reds; i++) { cin >> pos_blue_houses[i]; }
for (auto i = 0; i < reds; i++) { cin >> pos_red_houses[i]; }
for (auto i = 0; i < n - reds - 1; i++) { cin >> pos_blue_shops[i]; }
for (auto i = 0; i < reds + 1; i++) { cin >> pos_red_shops[i]; }
cout << "Case #" << test_case << endl;
cout << minimum_total_movement_length(n, reds, pos_blue_houses, pos_red_houses, pos_blue_shops, pos_red_shops) << endl;
}
}

View File

@@ -0,0 +1,39 @@
import java.io.StreamTokenizer
fun rectanglePermCount(n: Int, table: Array<Array<Int>>): Int {
var cnt = 0
for (r1 in 0 until n) {
for (c1 in 0 until n) {
for (r2 in r1 until n) {
for (c2 in c1 until n) {
val list: MutableList<Int> = mutableListOf()
for (i in r1..r2) {
for (j in c1..c2) {
list.add(table[i][j])
}
}
list.sort()
if (list.withIndex().all { it.index + 1 == it.value }) {
cnt++
}
}
}
}
}
return cnt
}
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
nextToken()
val n = nval.toInt()
val table = Array(n) { Array(n) { 0 } }
for (i in 0 until n) {
for (j in 0 until n) {
nextToken()
table[i][j] = nval.toInt()
}
}
println(rectanglePermCount(n, table))
}

View File

@@ -0,0 +1,29 @@
fun getMaximumEfficientModules(modules: List<Long>): List<Int> {
val sortedModules = modules.withIndex().sortedBy { it.value }
var maxEff = sortedModules[modules.size - 1].value * 3
var curEff = maxEff
var maxBound = modules.size - 1
for (i in modules.size - 2 downTo 0) {
val delta = 2 * sortedModules[i].value - sortedModules[i + 1].value
curEff += delta
if(curEff > maxEff) {
maxEff = curEff
maxBound = i
}
}
return sortedModules.slice(maxBound until sortedModules.size).map {
it.index + 1
}
}
fun main() = with(System.`in`.bufferedReader()) {
this.readLine()
val modules = this.readLine().split(" ").map { it.toLong() }
getMaximumEfficientModules(modules).run {
println(this.size)
println(this.joinToString(" "))
}
}

View File

@@ -0,0 +1,45 @@
fun main() = with(System.`in`.bufferedReader()) {
val n = this.readLine().toInt()
var locations = Array(n * n) { 0 to 0 }
for (i in 0 until n) {
this.readLine().split(" ").map { it.toInt() }.forEachIndexed { j, v ->
locations[v - 1] = i to j
}
}
//
var boxLeftTop = locations[0].first to locations[0].second
var boxRightTop = locations[0].first to locations[0].second
var boxLeftDown = locations[0].first to locations[0].second
var boxRightDown = locations[0].first to locations[0].second
var cnt = 1
for (item in 1 until n * n) {
val row = locations[item].first
val col = locations[item].second
if (boxLeftTop.first <= row && boxLeftTop.second >= col) {
boxLeftTop = row to col
}
if (boxRightTop.first <= row && boxRightTop.second <= col) {
boxRightTop = row to col
}
if (boxLeftDown.first >= row && boxLeftDown.second >= col) {
boxLeftDown = row to col
}
if (boxRightDown.first >= row && boxRightDown.second <= col) {
boxRightDown = row to col
}
if (boxLeftTop.first == boxRightTop.first && boxLeftDown.first == boxRightDown.first) {
if (boxLeftTop.second == boxLeftDown.second && boxRightTop.second == boxRightDown.second) {
if ((boxRightTop.first - boxLeftDown.first + 1) * (boxRightTop.second - boxLeftDown.second + 1) == item + 1) {
cnt++
}
}
}
}
println(cnt)
}

View File

@@ -0,0 +1,16 @@
import java.io.StreamTokenizer
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
nextToken()
val n = nval.toInt()
nextToken()
val m = nval.toInt()
val edges = (1..m).map {
nextToken()
val u = nval.toInt() - 1
nextToken()
val v = nval.toInt() - 1
nextToken()
val w = nval.toLong()
}
}

View File

@@ -0,0 +1,49 @@
import java.util.Stack
fun countNearestFarRelation(n: Int, edges: Array<MutableList<Pair<Int, Int>>>): Long {
val originXor = IntArray(n)
val deq = Stack<Pair<Int, Int>>()
deq.add(0 to 0)
while (deq.isNotEmpty()) {
val (now, before) = deq.pop()
for ((nxt, w) in edges[now]) {
if (nxt == before) {
continue
} else {
originXor[nxt] = originXor[now] xor w
deq.add(nxt to now)
}
}
}
originXor.sort()
var cnt: Long = 0
var before = -1
var cntSliced: Long = 0
for (i in originXor) {
if (i == before) {
cntSliced++
} else {
cnt += (cntSliced) * (cntSliced - 1) / 2
before = i
cntSliced = 1
}
}
cnt += (cntSliced) * (cntSliced - 1) / 2
return cnt
}
fun main() = with(System.`in`.bufferedReader()) {
val n = this.readLine().toInt()
var edges: Array<MutableList<Pair<Int, Int>>> = Array(n + 1) { mutableListOf() }
for (i in 0 until (n - 1)) {
val (u, v, w) = this.readLine().split(" ").map { it.toInt() }
edges[u - 1].add(v - 1 to w)
edges[v - 1].add(u - 1 to w)
}
println(countNearestFarRelation(n, edges))
}

View File

@@ -0,0 +1,20 @@
fun minCostAvoid(intervals: List<Pair<Int, Int>>, laserRanges: List<Pair<Int, Int>>): List<Pair<Int, Int>> {
val (n: Int, q: Int) = Pair(intervals.size, laserRanges.size)
}
fun main() = with(System.`in`.bufferedReader()) {
val (n, q) = this.readLine().split(' ').map { it.toInt() }
val intervals = (1..n).map {
val split = this.readLine().split(' ').map { it.toInt() }
Pair(split[0], split[1])
}
val laserRanges = (1..q).map {
val split = this.readLine().split(' ').map { it.toInt() }
Pair(split[0], split[1])
}
}

View File

@@ -0,0 +1,31 @@
import java.io.StreamTokenizer
fun calcs(maxCycle: Int, calcs: List<Pair<Int, Int>>, query: List<Int>) {
var sCalcs = calcs.sortedBy { it.first }
}
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
nextToken()
val n = nval.toInt()
nextToken()
val maxCycle = nval.toInt()
val calcs = (1..n).map {
nextToken()
val s = nval.toInt()
nextToken()
val e = nval.toInt()
Pair(s, e)
}
val q = nval.toInt()
val times = (1..q).map {
nextToken()
nval.toInt()
}
}

View File

@@ -0,0 +1,85 @@
import java.io.StreamTokenizer
const val K: Long = 1_000_000_007
fun find(parents: IntArray, a: Int): Int {
if (parents[a] == a) {
return a
}
parents[a] = find(parents, parents[a]);
return parents[a]
}
fun union(parents: IntArray, a: Int, b: Int) {
val ra = find(parents, a)
val rb = find(parents, b)
if (ra == rb) {
return
} else if (ra < rb) {
parents[rb] = ra
} else {
parents[ra] = rb
}
}
fun intervalPollutionArea(polluted: List<Long>): Pair<Int, Int> {
val parents = IntArray(polluted.size)
val poses = mutableListOf<Long>()
var now_x = 1L
var before_y = 0L
for ((i, p) in polluted.withIndex()) {
if (p <= before_y) {
now_x++
}
before_y = p
val now_pos: Long = K * now_x + p
poses.add(now_pos)
parents[i] = i
}
for ((i, p) in poses.withIndex()) {
val px = p / K
val py = p % K
val dx = listOf(
K * (px + 1) + py,
p + 1,
)
for (x in dx) {
val findPos = poses.binarySearch(x)
if (findPos > 0) {
union(parents, i, findPos)
}
}
}
return Pair(parents.map { find(parents, it) }.distinct().count(), polluted.size)
}
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
nextToken()
val n = nval.toInt()
val polluted = (1..n).map {
nextToken()
this.nval.toLong()
}
intervalPollutionArea(polluted).run {
println(this.first)
println(this.second)
}
}