Break through in 1 minute. Just write.
N, A, B = map(int, input().split())
print(N - A + B)
Break through in 3 minutes. Just write.
N, *x = map(int, open(0).read().split())
print(sum(abs(a) for a in x))
print(sum(a * a for a in x) ** 0.5)
print(max(abs(a) for a in x))
Break through in 3 minutes. Just write. If you know that you can turn to the square root of N, it shouldn't be difficult.
N = int(input())
result = set()
for i in range(1, int(N ** 0.5) + 1):
if N % i == 0:
result.add(i)
result.add(N // i)
print(*sorted(result), sep='\n')
Break through in 14 minutes. It takes too long. It is clearer than looking at the fire that a naive code that simulates obediently will result in a TLE when B is small. When it comes to * A
is better than + B
. Settle on the conclusion that you should just do * A
while the increment is small and add the rest together. Since A is at least 2, you can simulate it obediently * O * (log N) </ i>) So there is no problem.
X, Y, A, B = map(int, input().split())
result = 0
while X * A < Y and X * A < X + B:
X *= A
result += 1
result += ((Y - 1) - X) // B
print(result)
Postscript: I thought that there were many people who got penalized due to the D problem, but if I write it without devising, it is because X * A
overflows even with int64. I see.
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
defer flush()
X := readInt()
Y := readInt()
A := readInt()
B := readInt()
result := 0
for X <= (Y-1)/A && X*A < X+B {
X *= A
result++
}
result += ((Y - 1) - X) / B
println(result)
}
const (
ioBufferSize = 1 * 1024 * 1024 // 1 MB
)
var stdinScanner = func() *bufio.Scanner {
result := bufio.NewScanner(os.Stdin)
result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
result.Split(bufio.ScanWords)
return result
}()
func readString() string {
stdinScanner.Scan()
return stdinScanner.Text()
}
func readInt() int {
result, err := strconv.Atoi(readString())
if err != nil {
panic(err)
}
return result
}
var stdoutWriter = bufio.NewWriter(os.Stdout)
func flush() {
stdoutWriter.Flush()
}
func println(args ...interface{}) (int, error) {
return fmt.Fprintln(stdoutWriter, args...)
}
ABC180E - Traveling Salesman among Aerial Cities
It broke through in 39 and a half minutes. I solved it by copying the code of the ant book. I wonder if I could get the yellow performance if I copied it, shit.
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
using ll = long long;
using namespace std;
#define MAX_N 17
#define INF 2147483647
ll N;
ll dp[1 << MAX_N][MAX_N];
ll d[MAX_N][MAX_N];
void solve() {
rep(i, 1 << N) rep(j, N) dp[i][j] = INF;
dp[(1 << N) - 1][0] = 0;
for (int S = (1 << N) - 2; S >= 0; S--) {
for (int v = 0; v < N; v++) {
for (int u = 0; u < N; u++) {
dp[S][v] = min(dp[S][v], dp[S | 1 << u][u] + d[v][u]);
}
}
}
cout << dp[0][0] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
vector<ll> X(N), Y(N), Z(N);
rep(i, N) {
cin >> X[i] >> Y[i] >> Z[i];
}
rep(i, N) {
rep(j, N) {
d[i][j] = abs(X[i] - X[j]) + abs(Y[i] - Y[j]) + max(0ll, Z[i] - Z[j]);
}
}
solve();
return 0;
}
Recommended Posts