baekjoon 20260127

This commit is contained in:
songyc macbook 2026-01-27 20:55:03 +09:00
parent 169fcca00e
commit 507cba2f3b
3 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,17 @@
#include <stdio.h>
int count[26];
int main() {
char s[101];
scanf("%s", s);
int i=0;
while(s[i] !='\0') {
count[s[i++] - 'a']++;
}
for(int j=0; j<26; j++) printf("%d ",count[j]);
return 0;
}

View File

@ -0,0 +1,80 @@
import Foundation
final class FileIO {
private let buffer:[UInt8]
private var index: Int = 0
init(fileHandle: FileHandle = FileHandle.standardInput) {
buffer = Array(try! fileHandle.readToEnd()!) + [UInt8(0)]
}
@inline(__always) private func read() -> UInt8 {
defer { index += 1 }
return buffer[index]
}
@inline(__always) func readInt() -> Int {
var sum = 0
var now = read()
var isPositive = true
while now == 10 || now == 32 { now = read() }
if now == 45 { isPositive = false; now = read() }
while now >= 48, now <= 57 {
sum = sum * 10 + Int(now-48)
now = read()
}
return sum * (isPositive ? 1 : -1)
}
}
let input = FileIO()
var ans: [String] = []
func solve() -> String {
let (N, K) = (input.readInt(), input.readInt())
var build_time: [Int] = [0]
for _ in 0..<N {
build_time.append(input.readInt())
}
var pre_build_info: [[Int]] = Array(repeating: [], count: N+1)
for _ in 0..<K {
let (X, Y) = (input.readInt(), input.readInt())
pre_build_info[Y].append(X)
}
let W = input.readInt()
var dp: [Int] = Array(repeating: -1, count: N+1)
func build(_ n: Int) -> Int {
if dp[n] == -1 {
var total_time = 0
for prev in pre_build_info[n] {
total_time = max(total_time, build(prev))
}
dp[n] = total_time + build_time[n]
}
return dp[n]
}
return String(build(W))
}
func main() {
let T = input.readInt()
for _ in 0..<T {
ans.append(solve())
}
print(ans.joined(separator: "\n"))
}
main()

View File

@ -0,0 +1,65 @@
func solve() {
guard let n = Int(readLine() ?? "") else { return }
var A: [Int] = [Int]()
var B: [Int] = [Int]()
var C: [Int] = [Int]()
var D: [Int] = [Int]()
for _ in 0..<n {
guard let input = readLine() else { break }
let ABCD = input.split(separator: " ").compactMap{Int($0)}
guard ABCD.count == 4 else { break }
A.append(ABCD[0])
B.append(ABCD[1])
C.append(ABCD[2])
D.append(ABCD[3])
}
var AB: [Int] = [Int]()
var CD: [Int] = [Int]()
for i in 0..<n {
for j in 0..<n {
AB.append(A[i] + B[j])
CD.append(C[i] + D[j])
}
}
AB.sort()
CD.sort(by: >)
var (pAB, pCD) = (0, 0)
let (nAB, nCD) = (AB.count, CD.count)
var ans = 0
while pAB < nAB && pCD < nCD {
let (ab, cd) = (AB[pAB], CD[pCD])
if ab + cd > 0 {
pCD += 1
}
else if ab + cd < 0 {
pAB += 1
}
else {
var countAB = 0
while pAB < nAB && ab == AB[pAB] {
pAB += 1
countAB += 1
}
var countCD = 0
while pCD < nCD && cd == CD[pCD] {
pCD += 1
countCD += 1
}
ans += countAB * countCD
}
}
print(ans)
}
solve()