src
stringlengths 95
64.6k
| complexity
stringclasses 7
values | problem
stringlengths 6
50
| from
stringclasses 1
value |
---|---|---|---|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static BufferedReader reader;
static StringTokenizer st;
private static void setReader() {
reader = new BufferedReader(new InputStreamReader(System.in));
}
private static void updateST() throws IOException {
if (st==null || !st.hasMoreElements()) st = new StringTokenizer(reader.readLine());
}
private static int nextInt() throws IOException {
updateST();
return Integer.parseInt(st.nextToken());
}
public static void main(String[] args) throws IOException {
setReader();
int n = nextInt(), MOD = nextInt();
long[] pow = new long[n+2];
pow[0] = 1;
for (int i=1; i<=n+1; i++) pow[i] = (pow[i-1] * 2) % MOD;
long[][] C = new long[n+2][n+2];
for (int i=0; i<=n+1; i++) {
C[i][0] = 1;
for (int j=1; j<=i; j++) {
C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
}
}
long[][] dp = new long[n+2][n+1];
dp[0][0] = 1;
for (int i=0; i<=n; i++) {
for (int j=0; j<=i; j++) {
for (int k=1; i + k + 1 <= n + 1; k++) {
dp[i + k + 1][j + k]+=(((dp[i][j] * C[j + k][k]) % MOD * pow[k-1]) % MOD);
dp[i + k + 1][j + k]%=MOD;
}
}
}
long res = 0;
for (int i=0; i<=n; i++) res = (res + dp[n+1][i]) % MOD;
System.out.println(res);
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class phoenix_and_computers {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] st = br.readLine().split(" ");
int n = Integer.parseInt(st[0]);
int m = Integer.parseInt(st[1]);
long[][] ncr = ncrcoll(405, 405, m);
int[] p2 = new int[n + 1];
p2[0] = 1;
for (int i = 1; i < p2.length; i++) {
p2[i] = 2 * p2[i - 1] % m;
}
long[][] dp = new long[405][405];
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
for (int k = 1; i + k <= n; k++) {
dp[i + k + 1][j + k] += ((dp[i][j] * p2[k - 1]) % m * ncr[j + k][k]);
dp[i + k + 1][j + k] %= m;
}
}
}
long ans = 0;
for (int i = 0; i <= n; i++) {
ans = (ans + dp[n + 1][i]) % m;
}
System.out.println(ans);
}
static long[][] ncrcoll(int n, int k, int p) {
long[][] arr = new long[n + 1][k + 1];
for (int i = 1; i < arr.length; i++) {
arr[i][0] = 1;
}
for (int i = 1; i < arr.length; i++) {
for (int j = 1; j <= i && j < arr[0].length; j++) {
if (i == 1 && j == 1) {
arr[i][j] = 1;
} else {
arr[i][j] = (arr[i - 1][j] + arr[i - 1][j - 1]) % (p);
}
}
}
return arr;
}
public static long xpown(long x, long n) {
long res = 1;
while (n > 0) {
if (n % 2 != 0) {
res = (res * x) % 1000000007;
n--;
} else {
x = (x * x) % 1000000007;
n = n / 2;
}
}
return res;
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) throws Exception {
Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
thread.start();
thread.join();
}
static class TaskAdapter implements Runnable {
@Override
public void run() {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
EPhoenixAndComputers solver = new EPhoenixAndComputers();
solver.solve(1, in, out);
out.close();
}
}
static class EPhoenixAndComputers {
public void solve(int testNumber, FastInput in, FastOutput out) {
int n = in.ri();
int mod = in.ri();
CachedPow2 cp = new CachedPow2(2, mod, n + 1, mod - 1);
Combination comb = new Combination(n + 1, mod);
long[][][] dp = new long[n + 1][n + 1][2];
dp[0][0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j][0] = dp[i - 1][j][1];
for (int k = 0; k < i; k++) {
int len = i - k;
int last = j - len;
if (last >= 0) {
dp[i][j][1] += dp[k][last][0] * cp.pow(len - 1) % mod * comb.combination(j, len) % mod;
}
}
dp[i][j][1] %= mod;
}
}
long ans = 0;
for (int i = 0; i <= n; i++) {
ans += dp[n][i][1];
}
ans %= mod;
out.println(ans);
}
}
static class FastOutput implements AutoCloseable, Closeable, Appendable {
private static final int THRESHOLD = 32 << 10;
private final Writer os;
private StringBuilder cache = new StringBuilder(THRESHOLD * 2);
public FastOutput append(CharSequence csq) {
cache.append(csq);
return this;
}
public FastOutput append(CharSequence csq, int start, int end) {
cache.append(csq, start, end);
return this;
}
private void afterWrite() {
if (cache.length() < THRESHOLD) {
return;
}
flush();
}
public FastOutput(Writer os) {
this.os = os;
}
public FastOutput(OutputStream os) {
this(new OutputStreamWriter(os));
}
public FastOutput append(char c) {
cache.append(c);
afterWrite();
return this;
}
public FastOutput append(long c) {
cache.append(c);
afterWrite();
return this;
}
public FastOutput println(long c) {
return append(c).println();
}
public FastOutput println() {
return append('\n');
}
public FastOutput flush() {
try {
// boolean success = false;
// if (stringBuilderValueField != null) {
// try {
// char[] value = (char[]) stringBuilderValueField.get(cache);
// os.write(value, 0, cache.length());
// success = true;
// } catch (Exception e) {
// }
// }
// if (!success) {
os.append(cache);
// }
os.flush();
cache.setLength(0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return this;
}
public void close() {
flush();
try {
os.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
public String toString() {
return cache.toString();
}
}
static interface IntegerEntryIterator {
boolean hasNext();
void next();
int getEntryKey();
int getEntryValue();
}
static class FastInput {
private final InputStream is;
private byte[] buf = new byte[1 << 13];
private int bufLen;
private int bufOffset;
private int next;
public FastInput(InputStream is) {
this.is = is;
}
private int read() {
while (bufLen == bufOffset) {
bufOffset = 0;
try {
bufLen = is.read(buf);
} catch (IOException e) {
bufLen = -1;
}
if (bufLen == -1) {
return -1;
}
}
return buf[bufOffset++];
}
public void skipBlank() {
while (next >= 0 && next <= 32) {
next = read();
}
}
public int ri() {
return readInt();
}
public int readInt() {
boolean rev = false;
skipBlank();
if (next == '+' || next == '-') {
rev = next == '-';
next = read();
}
int val = 0;
while (next >= '0' && next <= '9') {
val = val * 10 - next + '0';
next = read();
}
return rev ? val : -val;
}
}
static class Hasher {
private long time = System.nanoTime() + System.currentTimeMillis() * 31L;
public int shuffle(long z) {
z += time;
z = (z ^ (z >>> 33)) * 0x62a9d9ed799705f5L;
return (int) (((z ^ (z >>> 28)) * 0xcb24d0a5c88c35b3L) >>> 32);
}
public int hash(int x) {
return shuffle(x);
}
}
static class CachedEulerFunction {
private static int boundary = 1 << 16;
private static int[] euler = MultiplicativeFunctionSieve.getInstance(boundary).getEuler();
private static IntegerHashMap map = new IntegerHashMap(64, true);
public static int get(int x) {
return get(x, 2);
}
private static int get(int x, int begin) {
if (x <= boundary) {
return euler[x];
}
int ans = map.getOrDefault(x, -1);
if (ans == -1) {
int factor = findPrimeFactor(x, begin);
int y = x;
int exp = 1;
while (y % factor == 0) {
y /= factor;
exp *= factor;
}
ans = get(y, factor + 1) * (exp - exp / factor);
//ans = calc(x);
map.put(x, ans);
}
return ans;
}
private static int findPrimeFactor(int x, int begin) {
for (int i = Math.max(2, begin); i * i <= x; i++) {
if (x % i == 0) {
return i;
}
}
return x;
}
}
static interface IntCombination {
}
static class MultiplicativeFunctionSieve {
static MultiplicativeFunctionSieve instance = new MultiplicativeFunctionSieve(1 << 16);
public int[] primes;
public boolean[] isComp;
public int primeLength;
public int[] smallestPrimeFactor;
public int[] expOfSmallestPrimeFactor;
int limit;
public static MultiplicativeFunctionSieve getInstance(int n) {
if (n <= (1 << 16)) {
return instance;
}
return new MultiplicativeFunctionSieve(n);
}
public int[] getEuler() {
int[] euler = new int[limit + 1];
euler[1] = 1;
for (int i = 2; i <= limit; i++) {
if (!isComp[i]) {
euler[i] = i - 1;
} else {
if (expOfSmallestPrimeFactor[i] == i) {
euler[i] = i - i / smallestPrimeFactor[i];
} else {
euler[i] = euler[expOfSmallestPrimeFactor[i]] * euler[i / expOfSmallestPrimeFactor[i]];
}
}
}
return euler;
}
public MultiplicativeFunctionSieve(int limit) {
this.limit = limit;
isComp = new boolean[limit + 1];
primes = new int[limit + 1];
expOfSmallestPrimeFactor = new int[limit + 1];
smallestPrimeFactor = new int[limit + 1];
primeLength = 0;
for (int i = 2; i <= limit; i++) {
if (!isComp[i]) {
primes[primeLength++] = i;
expOfSmallestPrimeFactor[i] = smallestPrimeFactor[i] = i;
}
for (int j = 0, until = limit / i; j < primeLength && primes[j] <= until; j++) {
int pi = primes[j] * i;
smallestPrimeFactor[pi] = primes[j];
expOfSmallestPrimeFactor[pi] = smallestPrimeFactor[i] == primes[j]
? (expOfSmallestPrimeFactor[i] * expOfSmallestPrimeFactor[primes[j]])
: expOfSmallestPrimeFactor[primes[j]];
isComp[pi] = true;
if (i % primes[j] == 0) {
break;
}
}
}
}
}
static class Factorial {
int[] fact;
int[] inv;
int mod;
public int getMod() {
return mod;
}
public Factorial(int[] fact, int[] inv, int mod) {
this.mod = mod;
this.fact = fact;
this.inv = inv;
fact[0] = inv[0] = 1;
int n = Math.min(fact.length, mod);
for (int i = 1; i < n; i++) {
fact[i] = i;
fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);
}
if (n - 1 >= 0) {
inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();
}
for (int i = n - 2; i >= 1; i--) {
inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);
}
}
public Factorial(int limit, int mod) {
this(new int[Math.min(limit + 1, mod)], new int[Math.min(limit + 1, mod)], mod);
}
public int fact(int n) {
if (n >= mod) {
return 0;
}
return fact[n];
}
public int invFact(int n) {
if (n >= mod) {
throw new IllegalArgumentException();
}
return inv[n];
}
}
static class CachedPow2 {
private int[] first;
private int[] second;
private int mod;
private int low;
private int mask;
private int phi;
private int xphi;
public CachedPow2(int x, int mod) {
this(x, mod, CachedEulerFunction.get(mod));
}
public CachedPow2(int x, int mod, int phi) {
this(x, mod, mod, phi);
}
public CachedPow2(int x, int mod, int limit, int phi) {
this.phi = phi;
limit = Math.min(limit, mod);
this.mod = mod;
int log = Log2.ceilLog(limit + 1);
low = (log + 1) / 2;
mask = (1 << low) - 1;
first = new int[1 << low];
second = new int[1 << log - low];
first[0] = 1;
for (int i = 1; i < first.length; i++) {
first[i] = (int) ((long) x * first[i - 1] % mod);
}
second[0] = 1;
long step = (long) x * first[first.length - 1] % mod;
for (int i = 1; i < second.length; i++) {
second[i] = (int) (second[i - 1] * step % mod);
}
xphi = DigitUtils.modPow(x, phi, mod);
}
public int pow(int exp) {
return (int) ((long) first[exp & mask] * second[exp >> low] % mod);
}
}
static class DigitUtils {
private DigitUtils() {
}
public static int mod(long x, int mod) {
if (x < -mod || x >= mod) {
x %= mod;
}
if (x < 0) {
x += mod;
}
return (int) x;
}
public static int mod(int x, int mod) {
if (x < -mod || x >= mod) {
x %= mod;
}
if (x < 0) {
x += mod;
}
return x;
}
public static int modPow(int x, long n, int m) {
if (n == 0) {
return DigitUtils.mod(1, m);
}
int ans = modPow(x, n / 2, m);
ans = DigitUtils.mod((long) ans * ans, m);
if (n % 2 == 1) {
ans = DigitUtils.mod((long) ans * x, m);
}
return ans;
}
}
static class Combination implements IntCombination {
final Factorial factorial;
int modVal;
public Combination(Factorial factorial) {
this.factorial = factorial;
this.modVal = factorial.getMod();
}
public Combination(int limit, int mod) {
this(new Factorial(limit, mod));
}
public int combination(int m, int n) {
if (n > m || n < 0) {
return 0;
}
return (int) ((long) factorial.fact(m) * factorial.invFact(n) % modVal * factorial.invFact(m - n) % modVal);
}
}
static class Log2 {
public static int ceilLog(int x) {
if (x <= 0) {
return 0;
}
return 32 - Integer.numberOfLeadingZeros(x - 1);
}
}
static class IntegerHashMap {
private int now;
private int[] slot;
private int[] version;
private int[] next;
private int[] keys;
private int[] values;
private int alloc;
private boolean[] removed;
private int mask;
private int size;
private boolean rehash;
private Hasher hasher = new Hasher();
public IntegerHashMap(int cap, boolean rehash) {
now = 1;
this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;
slot = new int[mask + 1];
version = new int[slot.length];
next = new int[cap + 1];
keys = new int[cap + 1];
values = new int[cap + 1];
removed = new boolean[cap + 1];
this.rehash = rehash;
}
private void doubleCapacity() {
int newSize = Math.max(next.length + 10, next.length * 2);
next = Arrays.copyOf(next, newSize);
keys = Arrays.copyOf(keys, newSize);
values = Arrays.copyOf(values, newSize);
removed = Arrays.copyOf(removed, newSize);
}
public void alloc() {
alloc++;
if (alloc >= next.length) {
doubleCapacity();
}
next[alloc] = 0;
removed[alloc] = false;
size++;
}
private void rehash() {
int[] newSlots = new int[Math.max(16, slot.length * 2)];
int[] newVersions = new int[newSlots.length];
int newMask = newSlots.length - 1;
for (int i = 0; i < slot.length; i++) {
access(i);
if (slot[i] == 0) {
continue;
}
int head = slot[i];
while (head != 0) {
int n = next[head];
int s = hash(keys[head]) & newMask;
next[head] = newSlots[s];
newSlots[s] = head;
head = n;
}
}
this.slot = newSlots;
this.version = newVersions;
now = 0;
this.mask = newMask;
}
private int hash(int x) {
return hasher.hash(x);
}
public void put(int x, int y) {
put(x, y, true);
}
public void put(int x, int y, boolean cover) {
int h = hash(x);
int s = h & mask;
access(s);
if (slot[s] == 0) {
alloc();
slot[s] = alloc;
keys[alloc] = x;
values[alloc] = y;
} else {
int index = findIndexOrLastEntry(s, x);
if (keys[index] != x) {
alloc();
next[index] = alloc;
keys[alloc] = x;
values[alloc] = y;
} else if (cover) {
values[index] = y;
}
}
if (rehash && size >= slot.length) {
rehash();
}
}
public int getOrDefault(int x, int def) {
int h = hash(x);
int s = h & mask;
access(s);
if (slot[s] == 0) {
return def;
}
int index = findIndexOrLastEntry(s, x);
return keys[index] == x ? values[index] : def;
}
private int findIndexOrLastEntry(int s, int x) {
int iter = slot[s];
while (keys[iter] != x) {
if (next[iter] != 0) {
iter = next[iter];
} else {
return iter;
}
}
return iter;
}
private void access(int i) {
if (version[i] != now) {
version[i] = now;
slot[i] = 0;
}
}
public IntegerEntryIterator iterator() {
return new IntegerEntryIterator() {
int index = 1;
int readIndex = -1;
public boolean hasNext() {
while (index <= alloc && removed[index]) {
index++;
}
return index <= alloc;
}
public int getEntryKey() {
return keys[readIndex];
}
public int getEntryValue() {
return values[readIndex];
}
public void next() {
if (!hasNext()) {
throw new IllegalStateException();
}
readIndex = index;
index++;
}
};
}
public String toString() {
IntegerEntryIterator iterator = iterator();
StringBuilder builder = new StringBuilder("{");
while (iterator.hasNext()) {
iterator.next();
builder.append(iterator.getEntryKey()).append("->").append(iterator.getEntryValue()).append(',');
}
if (builder.charAt(builder.length() - 1) == ',') {
builder.setLength(builder.length() - 1);
}
builder.append('}');
return builder.toString();
}
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Main{
static long MOD = 1_000_000_007L;
//static long MOD = 998_244_353L;
//static long MOD = 1_000_000_033L;
static long inv2 = (MOD + 1) / 2;
static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
static long lMax = 0x3f3f3f3f3f3f3f3fL;
static int iMax = 0x3f3f3f3f;
static HashMap <Long, Long> memo = new HashMap();
static MyScanner sc = new MyScanner();
//static ArrayList <Integer> primes;
static int nn = 300000;
static long[] pow2;
static long [] fac;
static long [] pow;
static long [] inv;
static long [] facInv;
static int[] base;
static int[] numOfDiffDiv;
static int[] numOfDiv;
static ArrayList <Integer> primes;
//static int[] primes;
static int ptr = 0;
static boolean[] isPrime;
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
// Start writing your solution here. -------------------------------------
/*fac = new long[nn + 1];
fac[1] = 1;
for(int i = 2; i <= nn; i++)
fac[i] = fac[i - 1] * i % MOD;*/
/*pow2 = new long[nn + 1];
pow2[0] = 1L;
for(int i = 1; i <= nn; i++)
pow2[i] = pow2[i - 1] * 2L;*/
/*inv = new long[nn + 1];
inv[1] = 1;
for (int i = 2; i <= nn; ++i)
inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/
/*facInv = new long[nn + 1];
facInv[0] = facInv[1] = 1;
for (int i = 2; i <= nn; ++i)
facInv[i] = facInv[i - 1] * inv[i] % MOD;*/
/*numOfDiffDiv = new int[nn + 1];
for(int i = 2; i <= nn; i++)
if(numOfDiffDiv[i] == 0)
for(int j = i; j <= nn; j += i)
numOfDiv[j] ++;*/
/*numOfDiv = new int[nn + 1];
numOfDiv[1] = 1;
for(int i = 2; i <= nn; i++) {
for(int j = 2; j * j <= i; j++) {
if(i % j == 0) {
numOfDiv[i] = numOfDiv[i / j] + 1;
break;
}
}
}*/
//primes = sieveOfEratosthenes(100001);
/*
int t = 1;
//t = sc.ni();
while(t-- > 0) {
//boolean res = solve();
//out.println(res ? "YES" : "NO");
long res = solve();
out.println(res);
}*/
int t = 1, tt = 0;
//t = sc.ni();
for(int i = 1; i <40000; i++) squares.add(i * i);
while(tt++ < t) {
boolean res = solve();
//out.println("Case #" + tt + ": " + res);
//out.println(res ? "YES" : "NO");
}
out.close();
}
static HashSet <Integer> squares = new HashSet();
static boolean solve() {
/*String s = sc.nextLine();
char[] c = s.toCharArray();
int n = c.length;*/
//int n = sc.ni();
//long[] a = new long[n];
//for(int i = 0; i < n; i++) a[i] = sc.nl();
long res = 0;
int n = sc.ni();
long m = sc.nl();
long[][][] dp = new long[2][5][5];
long[][][] dp2 = new long[2][5][5];
dp[0][2][1] = dp[1][2][2] = dp2[0][1][1] = 1L;
for(int i = 3; i <= n; i++) {
long[][] bef = dp[0];
long[][] aft = dp[1];
long[][] nbef = new long[i + 3][i + 3];
long[][] naft = new long[i + 3][i + 3];
for(int len = 1; len <= i; len++) {
for(int ind = 1; ind <= len; ind++) {
nbef[len + 1][1] += bef[len][ind];
nbef[len + 1][ind + 1] -= bef[len][ind];
naft[len + 1][ind + 1] += bef[len][ind];
//naft[len + 1][len + 2] -= bef[len][ind];
naft[len + 1][ind + 1] += aft[len][ind];
//naft[len + 1][len + 2] -= aft[len][ind];
nbef[len + 1][1] += dp2[0][len][ind] + dp2[1][len][ind];
//nbef[len + 1][len + 2] -= dp2[0][len][ind] + dp2[1][len][ind];
}
}
for(int len = 1; len <= i; len++) {
for(int ind = 1; ind <= len; ind ++) {
nbef[len][ind] = (nbef[len][ind] + nbef[len][ind - 1] + 10000000L * m) % m;
naft[len][ind] = (naft[len][ind] + naft[len][ind - 1] + 10000000L * m) % m;
}
}
dp2 = dp;
dp = new long[][][]{nbef, naft};
}
for(long[] row: dp[0])
for(long i : row)
res += i;
for(long[] row: dp[1])
for(long i : row)
res += i;
out.println(res % m);
return false;
}
// edges to adjacency list by uwi
public static int[][] packU(int n, int[] from, int[] to) {
return packU(n, from, to, from.length);
}
public static int[][] packU(int n, int[] from, int[] to, int sup) {
int[][] g = new int[n][];
int[] p = new int[n];
for (int i = 0; i < sup; i++) p[from[i]]++;
for (int i = 0; i < sup; i++) p[to[i]]++;
for (int i = 0; i < n; i++) g[i] = new int[p[i]];
for (int i = 0; i < sup; i++) {
g[from[i]][--p[from[i]]] = to[i];
g[to[i]][--p[to[i]]] = from[i];
}
return g;
}
// tree diameter by uwi
public static int[] diameter(int[][] g) {
int n = g.length;
int f0 = -1, f1 = -1, d01 = -1;
int[] q = new int[n];
boolean[] ved = new boolean[n];
{
int qp = 0;
q[qp++] = 0; ved[0] = true;
for(int i = 0;i < qp;i++){
int cur = q[i];
for(int e : g[cur]){
if(!ved[e]){
ved[e] = true;
q[qp++] = e;
continue;
}
}
}
f0 = q[n-1];
}
{
int[] d = new int[n];
int qp = 0;
Arrays.fill(ved, false);
q[qp++] = f0; ved[f0] = true;
for(int i = 0;i < qp;i++){
int cur = q[i];
for(int e : g[cur]){
if(!ved[e]){
ved[e] = true;
q[qp++] = e;
d[e] = d[cur] + 1;
continue;
}
}
}
f1 = q[n-1];
d01 = d[f1];
}
return new int[]{d01, f0, f1};
}
public static long c(int n, int k) {
return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;
}
// SegmentTree range min/max query by uwi
public static class SegmentTreeRMQ {
public int M, H, N;
public int[] st;
public SegmentTreeRMQ(int n)
{
N = n;
M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
H = M>>>1;
st = new int[M];
Arrays.fill(st, 0, M, Integer.MAX_VALUE);
}
public SegmentTreeRMQ(int[] a)
{
N = a.length;
M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
H = M>>>1;
st = new int[M];
for(int i = 0;i < N;i++){
st[H+i] = a[i];
}
Arrays.fill(st, H+N, M, Integer.MAX_VALUE);
for(int i = H-1;i >= 1;i--)propagate(i);
}
public void update(int pos, int x)
{
st[H+pos] = x;
for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);
}
private void propagate(int i)
{
st[i] = Math.min(st[2*i], st[2*i+1]);
}
public int minx(int l, int r){
int min = Integer.MAX_VALUE;
if(l >= r)return min;
while(l != 0){
int f = l&-l;
if(l+f > r)break;
int v = st[(H+l)/f];
if(v < min)min = v;
l += f;
}
while(l < r){
int f = r&-r;
int v = st[(H+r)/f-1];
if(v < min)min = v;
r -= f;
}
return min;
}
public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}
private int min(int l, int r, int cl, int cr, int cur)
{
if(l <= cl && cr <= r){
return st[cur];
}else{
int mid = cl+cr>>>1;
int ret = Integer.MAX_VALUE;
if(cl < r && l < mid){
ret = Math.min(ret, min(l, r, cl, mid, 2*cur));
}
if(mid < r && l < cr){
ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));
}
return ret;
}
}
}
public static char[] rev(char[] a){char[] b = new char[a.length];for(int i = 0;i < a.length;i++)b[a.length-1-i] = a[i];return b;}
public static double dist(double a, double b){
return Math.sqrt(a * a + b * b);
}
public static long inv(long a){
return quickPOW(a, MOD - 2);
}
public class Interval {
int start;
int end;
public Interval(int start, int end) {
this.start = start;
this.end = end;
}
}
public static ArrayList<Integer> sieveOfEratosthenes(int n) {
boolean prime[] = new boolean[n + 1];
Arrays.fill(prime, true);
for (int p = 2; p * p <= n; p++) {
if (prime[p]) {
for (int i = p * 2; i <= n; i += p) {
prime[i] = false;
}
}
}
ArrayList<Integer> primeNumbers = new ArrayList<>();
for (int i = 2; i <= n; i++) {
if (prime[i]) {
primeNumbers.add(i);
}
}
return primeNumbers;
}
public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
public static int lowerBound(int[] a, int l, int r, int v)
{
if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
int low = l-1, high = r;
while(high-low > 1){
int h = high+low>>>1;
if(a[h] >= v){
high = h;
}else{
low = h;
}
}
return high;
}
public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
public static int rlowerBound(int[] a, int l, int r, int v)
{
if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
int low = l-1, high = r;
while(high-low > 1){
int h = high+low>>>1;
if(a[h] <= v){
high = h;
}else{
low = h;
}
}
return high;
}
public static long C(int n, int m)
{
if(m == 0 || m == n) return 1l;
if(m > n || m < 0) return 0l;
long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;
return res;
}
public static long quickPOW(long n, long m)
{
long ans = 1l;
while(m > 0)
{
if(m % 2 == 1)
ans = (ans * n) % MOD;
n = (n * n) % MOD;
m >>= 1;
}
return ans;
}
public static long quickPOW(long n, long m, long mod)
{
long ans = 1l;
while(m > 0)
{
if(m % 2 == 1)
ans = (ans * n) % mod;
n = (n * n) % mod;
m >>= 1;
}
return ans;
}
public static int gcd(int a, int b)
{
if(a % b == 0) return b;
return gcd(b, a % b);
}
public static long gcd(long a, long b)
{
if(a % b == 0) return b;
return gcd(b, a % b);
}
static class Randomized {
public static void shuffle(int[] data) {
shuffle(data, 0, data.length - 1);
}
public static void shuffle(int[] data, int from, int to) {
to--;
for (int i = from; i <= to; i++) {
int s = nextInt(i, to);
int tmp = data[i];
data[i] = data[s];
data[s] = tmp;
}
}
public static void shuffle(long[] data) {
shuffle(data, 0, data.length - 1);
}
public static void shuffle(long[] data, int from, int to) {
to--;
for (int i = from; i <= to; i++) {
int s = nextInt(i, to);
long tmp = data[i];
data[i] = data[s];
data[s] = tmp;
}
}
public static int nextInt(int l, int r) {
return RandomWrapper.INSTANCE.nextInt(l, r);
}
}
static class RandomWrapper {
private Random random;
public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());
public RandomWrapper() {
this(new Random());
}
public RandomWrapper(Random random) {
this.random = random;
}
public int nextInt(int l, int r) {
return random.nextInt(r - l + 1) + l;
}
}
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Global14 {
static PrintWriter out;
static Scanner sc;
static ArrayList<int[]>q,w,x;
static ArrayList<Integer>adj[];
static HashSet<Integer>primesH;
static boolean prime[];
//static ArrayList<Integer>a;
static HashSet<Long>tmp;
static int[][][]dist;
static boolean[]v;
static int[]a,b,c,d;
static Boolean[][]dp;
static char[][]mp;
static int A,B,n,m,h,ans,sum;
//static String a,b;
static long oo=(long)1e9+7;
public static void main(String[]args) throws IOException {
sc=new Scanner(System.in);
out=new PrintWriter(System.out);
//A();
//B();
//C();
//D();
E();
//F();
//G();
out.close();
}
private static void A() throws IOException {
int t=ni();
while(t-->0) {
int n=ni(),w=ni();
a=nai(n);
int sum=0;
for(int i=0;i<n;i++)sum+=a[i];
if(sum==w) {ol("NO");continue;}
if(sum<w) {
ol("YES");
disp2(a);continue;
}
Arrays.sort(a);
int cur=0;
for(int i=n-1;i>=0;i--) {
if(cur==w) {
int tmp=a[i+1];
a[i+1]=a[i];
a[i]=tmp;
break;
}
cur+=a[i];
}
ol("YES");
disp2(a);
}
}
static void B() throws IOException {
int t=ni();
while(t-->0) {
long n=nl();
if(n%2==0) {
n/=2;
int sq=(int)Math.sqrt(n);
if(sq*sq==n&&sq!=0) {
ol("YES");continue;
}
}
if(n%2==0) {
n/=2;
int sq=(int)Math.sqrt(n);
if(sq*sq==n&&sq!=0) {
ol("YES");continue;
}
}
ol("NO");
}
}
static void C() throws IOException{
int t=ni();
while(t-->0) {
int n=ni(),m=ni(),x=ni();
int[][]a=new int[n][2];
int mx=0;
for(int i=0;i<n;i++) {
a[i][0]=ni();
a[i][1]=i;
mx=Math.max(mx, a[i][0]);
}
Arrays.sort(a,(u,v)->u[0]-v[0]);
PriorityQueue<int[]>vals=new PriorityQueue<int[]>((u,v)->u[0]-v[0]);
int[]ans=new int[n];
//int grp=1;
vals.add(new int[] {a[0][0],1});
ans[a[0][1]]=1;
for(int i=1;i<n;i++) {
if(vals.size()<m) {
ans[a[i][1]]=vals.size()+1;
vals.add(new int[] {a[i][0],vals.size()+1});
mx=Math.max(mx, a[i][0]);
}else {
int[]p=vals.poll();
vals.add(new int[] {p[0]+a[i][0],p[1]});
ans[a[i][1]]=p[1];
mx=Math.max(mx, a[i][0]+p[0]);
}
}
if(mx-vals.peek()[0]>x)ol("NO");
else {
ol("YES");
for(int i=0;i<n;i++) {
out.print(ans[i]+" ");
}
ol("");
}
}
}
private static Boolean dp(int i, int j) {
if(j>sum/2)return false;
if(i==x.size()) {
return sum/2==j;
}
if(dp[i][j]!=null)return dp[i][j];
return dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);
}
static boolean isPrime(long n) {
if(n==2)return true;
if(n<2||n%2==0)return false;
for(long i=3L;i*i<n;i+=2l) {
long rem=(n%i);
if(rem==0)return false;
}
return true;
}
static void D() throws IOException {
int t=ni();
while(t-->0) {
int n=ni(),l=ni(),r=ni();
int[]occ1=new int[n+1];
a=nai(n);
for(int i=0;i<l;i++) {
occ1[a[i]]++;
}
int[]occ2=new int[n+1];
for(int i=l;i<n;i++) {
occ2[a[i]]++;
}
int base=Math.abs((n/2)-l);
int tk=0;
int[]lrg=l>r?occ1:occ2;
int[]sml=l<=r?occ1:occ2;
for(int i=0;i<=n&&tk<base;i++) {
int rem=base-tk;
int taken=Math.min(rem,
Math.max(0,(lrg[i]-sml[i])/2));
lrg[i]-=taken;
sml[i]+=taken;
tk+=taken;
}
for(int i=0;i<n&&tk<base;i++) {
if(lrg[i]<=sml[i])continue;
lrg[i]--;
sml[i]++;
tk++;
}
int c1=0,c2=0;
for(int i=0;i<=n;i++) {
if(lrg[i]>sml[i]) {
if(c1<0) {
int diff=Math.min(-c1, -sml[i]+lrg[i]);
lrg[i]-=diff;
c1+=diff;
}
int nd=lrg[i]-sml[i];
c2-=nd;
base+=nd;
sml[i]=lrg[i];
}else if(lrg[i]<sml[i]) {
if(c2<0) {
int diff=Math.min(-c2, sml[i]-lrg[i]);
sml[i]-=diff;
c2+=diff;
}
int nd=-lrg[i]+sml[i];
base+=nd;
c1-=nd;
lrg[i]=sml[i];
}
}
ol(base);
}
}
private static int bfs(int i, int j,int k) {
boolean [][]vis=new boolean[dist.length][dist[0].length];
Queue<int[]>q=new LinkedList<int[]>();
int mn=Integer.MAX_VALUE;
q.add(new int[] {i,j,0,0});
int[]dx=new int[] {-1,1,0,0};
int[]dy=new int[] {0,0,1,-1};
while(!q.isEmpty()) {
int []x=q.poll();
vis[x[0]][x[1]]=true;
int c=x[2];
if(c>k/2)continue;
if(c>0&&k%c==0&&(k/c)%2==0) {
mn=Math.min(mn,x[3]*k/c );
}
for(int a=0;a<4;a++) {
int nx=x[0]+dx[a];
int ny=x[1]+dy[a];
if(valid(nx,ny)&&!vis[nx][ny]) {
q.add(new int[] {nx,ny,c+1,x[3]+dist[x[0]][x[1]][a]});
}
}
}
return mn;
}
private static boolean valid(int nx, int ny) {
return nx>=0&&nx<dist.length&&ny>=0&&ny<dist[0].length;
}
static int gcd (int a, int b) {
return b==0?a:gcd (b, a % b);
}
static void E() throws IOException {
int t=1;
while(t-->0) {
int n=ni();
long oo=nl();
long fc[]=new long[n+1];
fc[0]=fc[1]=1l;
long []pow2=new long[n+1];
pow2[0]=1l;
for(int i=1;i<pow2.length;i++) {
pow2[i]=(pow2[i-1]*2l)%oo;
}
for(int i=2;i<fc.length;i++) {
fc[i]=(fc[i-1]*1l*i)%oo;
}
long ncr[][]=new long[n+1][n+1];
for(int i=0;i<=n;i++) {
for(int j=0;j<=i;j++) {
ncr[i][j]=i==0||j==0?1l:(ncr[i-1][j-1]+ncr[i-1][j])%oo;
}
}
long ans=0;
long dp[][]=new long[n+2][n+2];
dp[0][0]=1l;
for(int i=0;i<n;i++) {
for(int j=0;j<=i;j++) {
for(int k=1;i+k<=n;k++) {
dp[i+k+1][j+k]+=((dp[i][j]*pow2[k-1]%oo)*ncr[j+k][k])%oo;
dp[i+k+1][j+k]%=oo;
}
}
}
for(int i=0;i<=n;i++) {
ans=(ans+dp[n+1][i])%oo;
}
ol(""+ans);
//ol(""+pow2[3]);
}
}
static void F() throws IOException {
int t=ni();
while(t-->0) {
}
}
static void CC() throws IOException {
for(int kk=2;kk<21;kk++) {
ol(kk+" -------");
int n=kk;
int k=n-2;
int msk=1<<k;
int[]a=new int[k];
for(int i=0;i<a.length;i++)a[i]=i+2;
int mx=1;
int ms=0;
for(int i=1;i<msk;i++) {
long prod=1;
int cnt=0;
for(int j=0;j<a.length;j++) {
if(((i>>j)&1)!=0) {
prod*=a[j];
cnt++;
}
}
if(cnt>=mx&&prod%n==1) {
mx=cnt;
ms=i;
}
}
ol(mx==1?mx:mx+1);
out.print(1+" ");
long pr=1;
for(int j=0;j<a.length;j++) {
if(((ms>>j)&1)!=0) {
out.print(a[j]+" ");
pr*=a[j];
}
}
ol("");
ol("Prod: "+pr);
ol(n+"*"+((pr-1)/n)+" + "+1);
}
}
static int ni() throws IOException {
return sc.nextInt();
}
static double nd() throws IOException {
return sc.nextDouble();
}
static long nl() throws IOException {
return sc.nextLong();
}
static String ns() throws IOException {
return sc.next();
}
static int[] nai(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = sc.nextInt();
return a;
}
static long[] nal(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = sc.nextLong();
return a;
}
static int[][] nmi(int n,int m) throws IOException{
int[][]a=new int[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
a[i][j]=sc.nextInt();
}
}
return a;
}
static long[][] nml(int n,int m) throws IOException{
long[][]a=new long[n][m];
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
a[i][j]=sc.nextLong();
}
}
return a;
}
static void o(String x) {
out.print(x);
}
static void ol(String x) {
out.println(x);
}
static void ol(int x) {
out.println(x);
}
static void disp1(int []a) {
for(int i=0;i<a.length;i++) {
out.print(a[i]+" ");
}
out.println();
}
static void disp2(int []a) {
for(int i=a.length-1;i>=0;i--) {
out.print(a[i]+" ");
}
out.println();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public boolean hasNext() {return st.hasMoreTokens();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public double nextDouble() throws IOException {return Double.parseDouble(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public boolean ready() throws IOException {return br.ready(); }
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
/*
bts songs to dance to:
I need U
Run
ON
Filter
I'm fine
*/
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
public class x1515E
{
static long MOD;
public static void main(String hi[]) throws Exception
{
BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(infile.readLine());
int N = Integer.parseInt(st.nextToken());
MOD = Long.parseLong(st.nextToken());
fac = new long[401];
invfac = new long[401];
fac[0] = invfac[0] = 1L;
for(int i=1; i <= 400; i++)
{
fac[i] = (fac[i-1]*i)%MOD;
invfac[i] = power(fac[i], MOD-2, MOD);
}
long[] pow2 = new long[401];
for(int i=0; i <= 400; i++)
pow2[i] = power(2, i, MOD);
long[][] dp = new long[N+1][N+1];
for(int v=1; v <= N; v++)
{
dp[v][v] = pow2[v-1];
for(int k=1; k <= v; k++)
for(int block=1; block <= k; block++)
{
if(block == v)
continue;
long temp = (dp[v-block-1][k-block]*calc(k-block, block))%MOD;
temp = (temp*pow2[block-1])%MOD;
dp[v][k] += temp;
if(dp[v][k] >= MOD)
dp[v][k] -= MOD;
}
}
long res = 0L;
for(int v=1; v <= N; v++)
{
res += dp[N][v];
if(res >= MOD)
res -= MOD;
}
System.out.println(res);
}
static long[] fac, invfac;
public static long calc(int a, int b)
{
long res = (fac[a+b]*invfac[a])%MOD;
return (res*invfac[b])%MOD;
}
public static long power(long x, long y, long p)
{
//0^0 = 1
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class E {
static long mod;
static long[][] dp;
static int n;
static long[] nWaysToPlaceGroupOfSize;
public static void main(String[] args) {
FastScanner fs=new FastScanner();
n=fs.nextInt();
mod=fs.nextInt();
precomp();
dp=new long[n+1][n+1];
for (int i=0; i<dp.length; i++) Arrays.fill(dp[i], -1);
long ans=0;
for (int nXsLeft=2; nXsLeft<=n; nXsLeft++) {
long curAns=go(0, nXsLeft);
ans=add(ans, curAns);
}
System.out.println(ans);
}
static long go(int position, int nXsLeft) {
if (position==n) {
//last thing was skipped, impossible
return 0;
}
if (position==n+1) {
//last thing was included, 1 way of doing that
if (nXsLeft==0) return 1;
return 0;
}
if (dp[position][nXsLeft]!=-1) {
return dp[position][nXsLeft];
}
//TODO: brute force number of xs to place
long ways=0;
for (int nPlace=1; nPlace<=Math.min(nXsLeft, n-position); nPlace++) {
long futureWays=go(position+nPlace+1, nXsLeft-nPlace);
long waysToPlaceMe=nCk(nXsLeft, nPlace);
if (nPlace>1) waysToPlaceMe=mul(waysToPlaceMe, nWaysToPlaceGroupOfSize[nPlace]);
ways=add(ways, mul(waysToPlaceMe, futureWays));
}
return dp[position][nXsLeft]=ways;
}
static long nCk(int n, int k) {
if (k>n) throw null;
return mul(facts[n], mul(factInvs[k], factInvs[n-k]));
}
static long add(long a, long b) {
return (a+b)%mod;
}
static long sub(long a, long b) {
return ((a-b)%mod+mod)%mod;
}
static long mul(long a, long b) {
return (a*b)%mod;
}
static long fastPow(long base, long e) {
if (e==0) return 1;
long half=fastPow(base, e/2);
if (e%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
static long[] facts=new long[1_000_00];
static long[] factInvs=new long[1_000_00];
static void precomp() {
facts[0]=1;
for (int i=1; i<facts.length; i++) facts[i]=mul(facts[i-1], i);
for (int i=0; i<factInvs.length; i++) factInvs[i]=fastPow(facts[i], mod-2);
nWaysToPlaceGroupOfSize=new long[500];
for (int finalSize=1; finalSize<nWaysToPlaceGroupOfSize.length; finalSize++) {
for (int firstPos=0; firstPos<finalSize; firstPos++) {
int l=firstPos, r=finalSize-1-firstPos;
nWaysToPlaceGroupOfSize[finalSize]=add(nWaysToPlaceGroupOfSize[finalSize], nCk(l+r, l));
}
}
System.err.println("Done with precomp.");
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
public class E14G {
static int[][] choose;
public static void main(String[] args) throws IOException {
init_io();
int N = nint(), M = nint();
choose = new int[N+1][];
long[] ways = new long[N+1];
ways[0] = 1; ways[1] = 1;
for (int i = 0; i <= N; i++) choose[i] = new int[i+1];
for (int i = 0; i <= N; i++) {
choose[i][0] = choose[i][i] = 1;
for (int j = 1; j < i; j++) {
choose[i][j] = (choose[i-1][j-1] + choose[i-1][j]) % M;
}
}
for (int i = 2; i <= N; i++) {
for (int j = 0; j < i; j++) {
ways[i] = (ways[i] + choose[i-1][j]) % M;
}
}
long[][] dp = new long[(N+1)/2+1][N+1];
dp[0][0] = 1;
for (int i = 1; i <= (N+1)/2; i++) {
for (int j = 1; j <= N; j++) {
for (int k = 1; k <= j; k++) {
dp[i][j] = (dp[i][j] + ways[k] * choose[j][k] % M * dp[i-1][j-k] % M) % M;
}
}
}
long ans = 0;
for (int i = 1; i <= (N+1)/2; i++) {
ans = (ans + dp[i][N-(i-1)]) % M;
}
out.println(ans);
out.close();
}
static StreamTokenizer in;
static PrintWriter out;
static BufferedReader br;
static int nint() throws IOException {
in.nextToken();
return (int) in.nval;
}
static void init_io() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
in = new StreamTokenizer(br);
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.util.*;
public class CF1515E extends PrintWriter {
CF1515E() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1515E o = new CF1515E(); o.main(); o.flush();
}
void main() {
int n = sc.nextInt();
int md = sc.nextInt();
int k = (n + 1) / 2;
int[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;
for (int h = 1; h <= k; h++)
for (int l = h; l <= n - h + 1; l++)
dp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);
int ans = 0;
for (int h = 1; h <= k; h++)
ans = (ans + dp[h][n - h + 1]) % md;
println(ans);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
@SuppressWarnings("unused")
public class Solution{
static long mod = -1;
static long[] fact, invfact, pow;
static long[][] C;
static long[][] dp;
static final int N = 405;
static int n;
public static void main(String[] args) throws IOException {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int tt = 1;
outer:
while(tt-->0) {
n = fs.nextInt();
mod = fs.nextLong();
dp = new long[N][N];
precompute();
dp[0][0] = 1;
for(int i=0;i<n;i++) {
for(int j=0;j<=i;j++) {
for(int k=1;i+k<=n;k++) {
dp[i+k+1][j+k] += (((dp[i][j]*pow[k-1])%mod)*C[j+k][k])%mod;
dp[i+k+1][j+k] %= mod;
}
}
}
long ans = 0;
for(int i=0;i<=n;i++) {
ans = (ans + dp[n+1][i])%mod;
}
out.println(ans);
}
out.close();
}
static void precompute() {
fact = new long[N]; invfact = new long[N]; C = new long[N][N]; pow = new long[N];
fact[0] = 1;
for(int i=1;i<=n;i++) fact[i] = (fact[i-1]*i)%mod;
invfact[n] = inv(fact[n]);
for(int i=n-1;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
pow[0] = 1;
for(int i=1;i<=n;i++) pow[i] = (pow[i-1]*2)%mod;
for(int i=1;i<=n;i++) {
for(int j=0;j<=i;j++) {
if(j==0 || j==i) C[i][j] = 1;
else C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod;
}
}
}
static long exp(long a, long n) {
long res = 1;
while(n>0) {
if((n&1)==1) res = (res*a)%mod;
a = (a*a)%mod;
n = n>>1;
}
return res;
}
static long inv(long n) {
return exp(n, mod-2);
}
static final Random random=new Random();
static <T> void shuffle(T[] arr) {
int n = arr.length;
for(int i=0;i<n;i++ ) {
int k = random.nextInt(n);
T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;
}
}
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n); int temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(long[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n); long temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static void reverse(int[] arr, int l, int r) {
for(int i=l;i<l+(r-l)/2;i++){
int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
}
}
static void reverse(long[] arr, int l, int r) {
for(int i=l;i<l+(r-l)/2;i++){
long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
}
}
static <T> void reverse(T[] arr, int l, int r) {
for(int i=l;i<l+(r-l)/2;i++) {
T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
}
}
static class FastScanner{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next(){
while(!st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
} catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt(){
return Integer.parseInt(next());
}
public int[] readArray(int n){
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = nextInt();
return a;
}
public long nextLong() {
return Long.parseLong(next());
}
public char nextChar() {
return next().toCharArray()[0];
}
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
// Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new FastScanner();
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int Int() {
return Integer.parseInt(next());
}
long Long() {
return Long.parseLong(next());
}
String Str(){
return next();
}
}
public static void main (String[] args) throws java.lang.Exception {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int T=1;
for(int t=0;t<T;t++){
int n=Int(),m=Int();
Solution sol=new Solution(out);
sol.solution(n,m);
}
out.close();
}
public static int Int(){
return fs.Int();
}
public static long Long(){
return fs.Long();
}
public static String Str(){
return fs.Str();
}
}
class Solution{
PrintWriter out;
public Solution(PrintWriter out){
this.out=out;
}
public void solution(int n,int mod){
long res=0;
long ncr[][]=new long[501][501];
long pow[]=new long[501];
pow[0]=1;
for(int i=1;i<pow.length;i++){
pow[i]=(pow[i-1]*2)%mod;
}
ncr[0][0]=1;
for (int i=1;i<ncr.length;i++) {
ncr[i][0]=1;
for (int j=1;j<ncr[0].length;j++) {
ncr[i][j]=(ncr[i-1][j]+ncr[i-1][j-1])%mod;
}
}
long dp[][]=new long[n+1][n+1];
for(int i=1;i<dp.length;i++){
dp[i][i]=pow[i-1];
for(int j=1;j<i;j++){
for(int k=1;k<i;k++){
//pow[cnt-1]
if(i-k-1>=1&&j>=k){
dp[i][j]=dp[i][j]+dp[i-k-1][j-k]*((ncr[j][k]*pow[k-1])%mod);
dp[i][j]%=mod;
}
}
}
}
for(int i=1;i<=n;i++){
res+=dp[n][i];
res%=mod;
}
out.println(res);
}
}
/*
;\
|' \
_ ; : ;
/ `-. /: : |
| ,-.`-. ,': : |
\ : `. `. ,'-. : |
\ ; ; `-.__,' `-.|
\ ; ; ::: ,::'`:. `.
\ `-. : ` :. `. \
\ \ , ; ,: (\
\ :., :. ,'o)): ` `-.
,/,' ;' ,::"'`.`---' `. `-._
,/ : ; '" `;' ,--`.
;/ :; ; ,:' ( ,:)
,.,:. ; ,:., ,-._ `. \""'/
'::' `:'` ,'( \`._____.-'"'
;, ; `. `. `._`-. \\
;:. ;: `-._`-.\ \`.
'`:. : |' `. `\ ) \
-hrr- ` ;: | `--\__,'
'` ,'
,-'
free bug dog
*/
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
// Main Code at the Bottom
import java.util.*;
import java.io.*;
public class Main{
//Fast IO class
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
boolean env=System.getProperty("ONLINE_JUDGE") != null;
//env=true;
if(!env) {
try {
br=new BufferedReader(new FileReader("src\\input.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
else br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static long MOD=(long)1e9+7;
//debug
static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
//Global variables and functions
static long memo[];
static long C[][];
static long exp(long a,long x) {
if(x==0) return 1;
if(x%2==0) return exp((a*a)%MOD,x/2)%MOD;
return ((a%MOD)*((exp((a*a)%MOD,x/2))%MOD))%MOD;
}
static void fill(int n) {
C = new long[n+1][n+1];
for(int i = 1; i<=n;i++) C[i][0]=C[i][i]=1;
for(int i=2;i<=n;i++) {
for(int j=1;j<=n;j++) {
C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
}
}
}
//Main function(The main code starts from here)
public static void main (String[] args) throws java.lang.Exception {
int test=1;
//test=sc.nextInt();
while(test-->0) {
int n = sc.nextInt();
MOD = sc.nextLong();
memo = new long[n+1];
fill(n);
long dp[][] = new long[n+5][n+5];
for(int i=1;i<=n;i++) dp[i][i]=exp(2,i-1);
for(int i = 2; i <= n; i++) {
for(int j = 1; j < i; j++) {
for(int k = 1; k <= j; k++) {
long val = (dp[i-k-1][j-k]*C[j][k])%MOD;
if(memo[k-1] ==0) memo[k-1] = exp(2, k-1);
val=(val*memo[k-1])%MOD;
dp[i][j]=(dp[i][j]+val)%MOD;
}
}
}
long ans = 0;
for(int i=0;i<=n;i++) ans=(ans+dp[n][i])%MOD;
out.println(ans);
}
out.flush();
out.close();
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.util.*;
import java.io.*;
public class Sol{
static class Pair implements Comparable<Pair>{
int x;int y;int value;
public Pair(int x,int y,int value) {
this.x=x;
this.y=y;
this.value=value;
}
@Override
public int compareTo(Pair p){return Long.compare(y,p.y); }
}
public static void main(String []args){
int t=1;
while(t-->0){
int n=ni();mod=nl();
precomp();
long dp[][]=new long[405][405];dp[0][0]=1l;
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
for(int k=1;k+i<=n;k++){
dp[i+k+1][j+k]+=((dp[i][j]*p2[k-1])%mod)*Comb[k+j][k];
dp[i+k+1][j+k]%=mod;
}
}
}
long sum=0l;
for(int i=0;i<=n;i++)sum=(sum+dp[n+1][i])%mod;
out.println(sum);
}out.close();}
//-----------------Utility--------------------------------------------
static long Comb[][]=new long[405][405];
static long p2[]=new long[405];
static long inv[]=new long[405];
static long factorial[]=new long[405];
static void precomp(){
inv[0]=1;factorial[0]=1l;
for(long i=1;i<405;i++){factorial[(int)i]=i*factorial[(int)i-1];factorial[(int)i]%=mod;}
for(int i=1;i<405;i++){ inv[i]=power(factorial[i],mod-2);}
for(int i=0;i<405;i++){
for(int j=0;j<=i;j++){
Comb[i][j]=(((factorial[i]*inv[j])%mod)*inv[i-j])%mod;
}
}
for(int i=0;i<405;i++)p2[i]=power(2,i);
}
static int Max=Integer.MAX_VALUE; static long mod=1000000007;
static int v(char c){return (int)(c-'a')+1;}
public static long power(long x, long y )
{
//0^0 = 1
long res = 1L;
x = x%mod;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%mod;
y >>= 1;
x = (x*x)%mod;
}
return res;
}
//--------------------------------------------------------------------
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static FastReader in=new FastReader(inputStream);
static PrintWriter out=new PrintWriter(outputStream);
static class FastReader
{
BufferedReader br;
StringTokenizer st;
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
public String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static int ni(){return in.nextInt();}
static long nl(){return in.nextLong();}
static String ns(){return in.nextLine();}
static int[] na(int n){int a[]=new int[n];for(int i=0;i<n;i++){a[i]=ni();} return a;}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
// practice with kaiboy, coached by rainboy
import java.io.*;
import java.util.*;
public class CF1515E extends PrintWriter {
CF1515E() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1515E o = new CF1515E(); o.main(); o.flush();
}
void main() {
int n = sc.nextInt();
int md = sc.nextInt();
int k = (n + 1) / 2;
int[][] dp = new int[k + 1][n + 1]; dp[0][0] = 1;
for (int h = 1; h <= k; h++)
for (int l = h; l <= n - h + 1; l++)
dp[h][l] = (int) ((dp[h][l - 1] * 2L + dp[h - 1][l - 1]) * h % md);
int ans = 0;
for (int h = 1; h <= k; h++)
ans = (ans + dp[h][n - h + 1]) % md;
println(ans);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class PhoenixAndComputers {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int mod = Integer.parseInt(st.nextToken());
long[][] dp = new long[n+2][n+1];
long[] pow = new long[n+1];
pow[0] = 1;
for (int i=1; i <= n; i++){
pow[i] = pow[i-1]*2;
pow[i] %= mod;
}
long[][] choose = new long[n*2+1][n+1];
for (int i=0; i <= n; i++){
choose[i][i] = 1;
}
for (int i=1; i <= n*2; i++){
for (int j=0; j <= n; j++){
choose[i][j] = choose[i-1][j];
if (j > 0){
choose[i][j] += choose[i-1][j-1];
}
choose[i][j] %= mod;
}
}
dp[0][0] = 1;
for (int i=0; i < n; i++){ // number of computers on
for (int j=0; j <= i; j++){ // number manually turned on
for (int k=1; k+i <= n; k++){ // number of computers manually turned on in next "block"
dp[i+k+1][j+k] += (pow[k-1] * choose[j+k][k])%mod * dp[i][j];
dp[i+k+1][j+k] %= mod;
}
}
}
long ans = 0;
for (int j=0; j <= n; j++){
ans += dp[n+1][j];
ans %= mod;
}
System.out.println(ans);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.util.*;
public class CF1515E extends PrintWriter {
CF1515E() { super(System.out, true); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1515E o = new CF1515E(); o.main(); o.flush();
}
int[] ff, gg; int md;
long ch(int n, int k) {
return (long) ff[n] * gg[k] % md * gg[n - k] % md;
}
long inv(int a) {
return a == 1 ? 1 : inv(a - md % a) * (md / a + 1) % md;
}
void main() {
int n = sc.nextInt();
md = sc.nextInt();
int[] p2 = new int[n];
for (int p = 1, i = 0; i < n; i++) {
p2[i] = p;
p = p * 2 % md;
}
ff = new int[n + 1];
gg = new int[n + 1];
long f = 1;
for (int i = 0; i <= n; i++) {
gg[i] = (int) inv(ff[i] = (int) f);
f = f * (i + 1) % md;
}
int[][] dp = new int[n + 1][n + 1]; dp[1][1] = 1; dp[2][2] = 2;
for (int u = 3; u <= n; u++)
for (int v = 1; v <= u; v++) {
long x = v == u ? p2[u - 1] : 0;
for (int k = 1; k < v && k <= u - 2; k++)
x += dp[u - k - 1][v - k] * ch(v, k) % md * p2[k - 1] % md;
dp[u][v] = (int) (x % md);
}
int ans = 0;
for (int v = 1; v <= n; v++)
ans = (ans + dp[n][v]) % md;
println(ans);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.util.Arrays;
import java.util.Scanner;
public class e1515 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
solve(s.nextInt(), s.nextLong());
}
public static long inv(long n, long mod) {
if (n == 1) return 1;
return (inv(mod % n, mod) * (mod - mod / n)) % mod;
}
public static void solve(int n, long mod) {
long fact[] = new long[n + 2];
long invFact[] = new long[n + 2];
long twoPow[] = new long[n + 2];
fact[0] = 1;
invFact[0] = 1;
twoPow[0] = 1;
for (int i = 1; i < n + 2; i++) {
fact[i] = (fact[i - 1] * i) % mod;
invFact[i] = (invFact[i - 1] * inv(i, mod)) % mod;
twoPow[i] = (2 * twoPow[i - 1]) % mod;
}
long dp[][] = new long[n + 2][];
dp[0] = new long[]{1};
long next[] = null;
for (int i = 1; i <= n + 1; i++) {
next = new long[i + 1];
for (int j = 0; j < i - 1; j++) {
for (int k = 0; k < dp[j].length; k++) {
next[k + i - j - 1] = (next[k + i - j - 1] + ((((dp[j][k] * twoPow[i - j - 2]) % mod * fact[k + i - j - 1]) % mod * invFact[k]) % mod * invFact[i - j - 1]) % mod) % mod;
}
}
dp[i] = next;
}
long sum = 0;
for (int i = 0; i < next.length; i++) {
sum = (sum + next[i]) % mod;
}
System.out.println(sum);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.awt.*;
import java.io.*;
import java.sql.Array;
import java.util.*;
import java.util.List;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static final int N=405;
static final int mod=1000000007;
static final int INF=1000000009;
static final int numBit=17;
static FastReader r=new FastReader();
static PrintWriter pw = new PrintWriter(System.out);
// call dp[i][j] is number ways can turn on i computer but we just turn on j computer manually.
static int [][]dp=new int[N][N];
static int []p2=new int[N];
static int []fac=new int[N];
static int []ifac=new int[N];
static int M;
public static int mul(int a,int b){
return (int)(1l*a*b%M);
}
public static int poww(int a,int b){
int r=1;
while(b>0){
if(b%2==1) r=mul(r,a);
a=mul(a,a);
b>>=1;
}
return r;
}
public static int inv(int x){
return poww(x,M-2);
}
public static int add(int a,int b){
a+=b;
if(a>=M) a-=M;
return a;
}
public static int bino(int n,int k){
return mul(fac[n],mul(ifac[n-k],ifac[k]));
}
public static void main(String[] args) throws IOException {
int n=r.nextInt();
M=r.nextInt();
fac[0]=1;
ifac[0]=1;
p2[0]=1;
for(int i=1;i<=n;++i){
fac[i]=mul(fac[i-1],i);
ifac[i]=inv(fac[i]);
p2[i]=mul(p2[i-1],2);
}
int ans=0;
dp[0][0]=1;
for(int i=0;i<=n;++i){
for(int k=0;k<=i;++k){
for(int j=1;j<=n-i+1;++j){
dp[i+j+1][k+j]=add(dp[i+j+1][k+j],mul(dp[i][k],mul(p2[j-1],bino(j+k,j))));
}
}
}
for(int i=0;i<=n+1;++i){
ans=add(ans,dp[n+1][i]);
}
pw.print(ans);
pw.close();
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Practice {
public static long mod = (long) Math.pow(10, 9) + 7;
public static long[][] dp;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
String[] s2 = br.readLine().split(" ");
int n = (int) Long.parseLong(s2[0]);
long m = Long.parseLong(s2[1]);
dp = new long[n + 2][n + 2];
long[] power = new long[n + 1];
mod = m;
long[][] choose = new long[n + 2][n + 2];
getPow(power, n + 1);
getChoose(choose, n + 2, n + 2);
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
for (int k = 1; k + i <= n; k++) {
// System.out.println((j + k) + " " + k + " - " + choose[j + k][k]);
dp[i + k + 1][j
+ k] = (dp[i + k + 1][j + k] + (((dp[i][j] * power[k - 1]) % mod) * choose[j + k][k]) % mod)
% mod;
}
}
}
long ans = 0;
for (int i = 0; i <= n; i++) {
ans = (ans + dp[n + 1][i]) % mod;
}
pw.println(ans);
pw.close();
}
private static void getChoose(long[][] choose, int up, int dow) {
// TODO Auto-generated method stub
for (int i = 1; i < up; i++) {
for (int j = 1; j <= i; j++) {
if (j == 1 && i == 1) {
choose[i][j] = 1;
} else if (j == 1) {
choose[i][j] = i;
} else {
choose[i][j] = (choose[i - 1][j] + choose[i - 1][j - 1]) % mod;
}
}
}
}
private static void getPow(long[] power, int l) {
// TODO Auto-generated method stub
for (int i = 0; i < l; i++) {
if (i == 0) {
power[i] = 1;
} else {
power[i] = (power[i-1] * 2) % mod;
}
}
}
}
//private static long getGCD(long l, long m) {
//// TODO Auto-generated method stub
//
//long t1 = Math.min(l, m);
//long t2 = Math.max(l, m);
//while (true) {
// long temp = t2 % t1;
// if (temp == 0) {
// return t1;
// }
// t2 = t1;
// t1 = temp;
//}
//} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.util.*;
import java.io.*;
public class _G14 {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = 1;
while (t-- > 0) {
int n = sc.nextInt();
mod = sc.nextLong();
long res = 0;
initFac(n + 7);
long [] tpow = new long[n + 7];
long [][] combo = new long[n + 6][n + 6];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i)
combo[i][j] = 1;
else
combo[i][j] = (combo[i - 1][j - 1] + combo[i - 1][j]) % mod;
}
}
tpow[0] = 1;
for (int i = 1; i <= n + 6; i++) tpow[i] = (tpow[i - 1] * 2) % mod;
// dp[i][auto]
long [][] dp = new long[n + 1][n + 1];
for (int i = 1; i <= n; i++) dp[i][0] = tpow[i - 1];
for (int i = 3; i <= n; i++) {
for (int auto = 1; auto <= n / 2; auto++) {
if (!check(i, auto)) continue;
long total = 0;
for (int j = i - 2; j >= 1; j--) {
if (!check(j, auto - 1)) break;
int len = i - j - 1;
long ways = tpow[len - 1];
int picked = j - (auto - 1);
long interleave = combo[len + picked][picked];
ways = (ways * interleave) % mod;
ways = (ways * dp[j][auto - 1]) % mod;
total = (total + ways) % mod;
}
dp[i][auto] = total;
if (i == n) res = (res + dp[i][auto]) % mod;
}
}
res = (res + dp[n][0]) % mod;
out.println(res);
}
out.close();
}
static boolean check(int n, int auto) {
int rem = n - auto;
int seg = auto + 1;
return rem >= seg;
}
static long[] fac;
static long mod;
static void initFac(long n) {
fac = new long[(int)n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (fac[i - 1] * i) % mod;
}
}
static long nck(int n, int k) {
if (n < k)
return 0;
long den = inv((int) (fac[k] * fac[n - k] % mod));
return fac[n] * den % mod;
}
static long pow(long b, long e) {
long ans = 1;
while (e > 0) {
if (e % 2 == 1)
ans = ans * b % mod;
e >>= 1;
b = b * b % mod;
}
return ans;
}
static long inv(long x) {
return pow(x, mod - 2);
}
static void sort(int[] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static void sort(long[] a) {
ArrayList<Long> q = new ArrayList<>();
for (long i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.util.*;
public class Etruco2 {
static String[] vals = {
"%S3L{PYzV1%SGI'>$/4Gam=^#ODu|`Q!Bys%Mw|?fA*0ti{r69RB1N`{B>YC;.:XEmm3t-i^N",
"#Y73mVxQ&J`inFO4.v<j?yg{4~O=p=t$'#UHQizDnbsn,+JyuS~@WKw0p*Gy%V:#sa5,L|9RX{",
"f0J*n]5ZaRg:d-;{f!Y47]i_'u'cTz*=K$b#=}w[U]3*f+$|4ePs'K?]p8~0loSL$h_+T^{+ik",
"@r),FzP0XP>vU2<s9GIJ;0K0e)b_Hwyaw2}n0-%|lUlV(kWB<nx7@M[30yXxR(n:5@CEc[~,B^o",
"0<2C[Fz1*3iganAet-6RW8/X&nnSUf`Tu5-$~<5}F~$e_n5j9jD^Kk)_Xh=)WG@{4:XC;V4a|X]*",
"(_gw]4[ktYOZ},E?GXG5h{UF<Fx1O$0YNdA0+5)7#j%f)=Ui|3p^tt:SV(N^mbR9.+!s4fy<.?WQ.",
"%-i=_PJtuHA63yU,f)Gh@#Z*;FIWjaXwKS*bq=EOMA9yc>OD+}xg{z`X.~atEmXp9Z~*u]I3_7IxDZ",
"#N,-ehU0na1kWpn=P9ZK{TRs/&@KgxaK4h+V/ea!9Y3QYy9ZL}n&pn>G+'I+]ekWM$(g'8ym$Mj+,?V",
"coyL[=Xb>wzL0z?{kW5GQjeWPCy6YU<B/?paWq?^7__LMh<{ZJ+8!o7I.=<2b)j-)f!Cwk7!Ojrs[Zs",
"A+If^46|x9Wfiv3OlqZAUE[u(p2nLL/x$!LmSrR4Do9+4oYG:0P-!#>g9'|axl=i;q`E:ja?MDOB<Gyk",
"1$8eKLgE'nM]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@4R&EVN&ksXYM]s3#P'~g2|AH/F-W.=DzIK1q0Xm$wO6S<>[Z59PNPzB6<cSBpt),4t>kqZk`(7._xvQFQp)ryD&vPW$U^,CDFk4n|;E):Us$s<Gy|Hk",
"%2e[;,B|/Eu/ZE4lNtcjC.R6.fe@z5%2PN<,:D:K)O5vAa,YxM#q{S}A:<DOs/uLs8DB&D^Sx>vxNSM-l.fH,S[lS):qrPY3lb!,g`l'A~Syu|(|0?pjXEY[wZXIOM$;zs??,~g]v0gR~Do3]>6d.4{c($[<Qv^Wiv![/,xru^c=lBuvpq:lbN:0(Or4[|i=pxfT&V:-N<YbgC)M4d*gNI3,!.:IIaA.E=WOUqxwXC,kboWnpgZLN_e9!&g-IP6K)Es3w]Z`V@Y,;>:j>?/d1huGG(aI|?Jc.o6Y#/<tl0zy>_+aJoxiU8%qIPkwPSTmjWt.ngDEk4U8GjT1~Z5hmHX8>wHskb1jo"};
static String chars = "!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
static int N = 400;
static long mod;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
long b = chars.length();
int n = sc.nextInt();
mod = sc.nextLong();
if(n > 110) {
char[] s = vals[n-111].toCharArray();
long res = 0;
for(char c: s) {
res *= b;
res += chars.indexOf(c);
res %= mod;
}
System.out.println(res);
}
else {
c = new long[N+1][N+1];
c[0][0] = 1;
for(int i = 0; i < n; i++){
c[i][0] = 1;
for(int j = 1; j <= i; j++){
c[i][j] = (c[i-1][j] + c[i-1][j-1]) % mod;
}
}
dpcl = new long[N+1][N+1];
dpop = new long[N+1][N+1];
for(int i = 0; i <= N; i++){
for(int j = 0; j <= N; j++){
dpcl[i][j] = -1;
dpop[i][j] = -1;
}
}
long res = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j <= n-1; j++){
for(int a = 0; a <= j; a++) {
long leftv = dpop(i, a);
long rightv = dpop(n-i-1, j-a);
long curr = leftv * rightv % mod;
long fac = c[j][a];
long v = curr * fac % mod;
res = (res + v) % mod;
}
}
}
System.out.println(res);
}
}
static long[][] c, dpcl, dpop;
static long dpcl(int n, int k) {
if(dpcl[n][k] >= 0) return dpcl[n][k];
if(n == 0 || n == 1) {
if(k == 0) {
return dpcl[n][k] = 1;
}
else {
return dpcl[n][k] = 0;
}
}
if(k == 0) { // n > 1
return dpcl[n][k] = 0;
}
long res = 0;
for(int i = 0; i < n; i++){
for(int a = 0; a <= k-1; a++) {
long leftv = dpcl(i, a);
long rightv = dpcl(n-i-1, k-1-a);
long curr = leftv * rightv % mod;
long fac = c[k-1][a];
long v = curr * fac % mod;
res = (res + v) % mod;
}
}
return dpcl[n][k] = res;
}
static long dpop(int n, int k) {
if(dpop[n][k] >= 0) return dpop[n][k];
if(n == 0) {
if(k == 0) {
return dpop[n][k] = 1;
}
else {
return dpop[n][k] = 0;
}
}
if(k == 0) { // n > 0
return dpop[n][k] = 0;
}
long res = 0;
for(int i = 0; i < n; i++){
for(int a = 0; a <= k-1; a++) {
long leftv = dpcl(i, a);
long rightv = dpop(n-i-1, k-1-a);
long curr = leftv * rightv % mod;
long fac = c[k-1][a];
long v = curr * fac % mod;
res = (res + v) % mod;
}
}
return dpop[n][k] = res;
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.util.*;
public class Compute {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long M = sc.nextInt();
long fact[] = new long[n+1];
long inv[] = new long[n+1];
long ifact[] = new long[n+1];
long dp[][] = new long[n+1][n+1];
fact[1] = 1;
ifact[1] = 1;
ifact[0] = 1;
inv[1] = 1;
dp[1][1] = 1;
for(int i = 2; i <= n; i++) {
fact[i] = (i*fact[i-1]) % M;
inv[i] = (inv[(int)(M % i)]*(M - M/i)) % M;
dp[i][i] = (dp[i-1][i-1] * 2) % M;
ifact[i] = (ifact[i-1]*inv[i]) % M;
}
for(int i = 3; i <= n; i++) {
for(int j = i/2 + 1; j <= i-1; j++) {
for(int k = 2; k <= i-1 && j-k+1 > (i-k)/2; k++) {
dp[i][j] = (dp[i][j] + ((((dp[k-1][k-1]*dp[i-k][j-k+1] % M)*fact[j] % M)*ifact[k-1] % M)*ifact[j-k+1] % M)) % M;
}
}
}
long sum = 0;
for(int i = n/2 + 1; i <= n; i++)
sum = (sum + dp[n][i]) % M;
System.out.println(sum % M);
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.util.*;
import java.io.*;
public class EdA {
static long[] mods = {1000000007, 998244353, 1000000009};
static long mod = mods[0];
public static MyScanner sc;
public static PrintWriter out;
public static void main(String[] havish) throws Exception{
// TODO Auto-generated method stub
sc = new MyScanner();
out = new PrintWriter(System.out);
int n = sc.nextInt();
mod = sc.nextLong();
long[] fact = new long[401];
long[] twopowers = new long[401];
fact[0] = 1;
twopowers[0] = 1;
for(int j = 1;j<=400;j++){
twopowers[j] = twopowers[j-1] * 2L;
twopowers[j] %= mod;
fact[j] = fact[j-1] * j;
fact[j] %= mod;
}
long[][] choose = new long[401][401];
for(int j = 0;j<=400;j++){
for(int k = 0;k<=j;k++){
choose[j][k] = fact[j];
choose[j][k] *= inv(fact[k]);
choose[j][k] %= mod;
choose[j][k] *= inv(fact[j-k]);
choose[j][k] %= mod;
}
}
long[][] dp = new long[n+1][n+1]; //prefix, # of autos
for(int j = 1;j<=n;j++){
dp[j][0] = twopowers[j-1];
}
for(int k = 0;k<n;k++){ //number of autos
for(int j = 1;j<=n;j++){ //prefix
if (k > j)
continue;
for(int add = 2; j+add <= n; add++){
long prod = dp[j][k] * choose[j-k+add-1][add-1];
prod %= mod;
prod *= twopowers[add-2];
dp[j+add][k+1] += prod;
dp[j+add][k+1] %= mod;
}
}
}
long ans = 0;
for(int s = 0;s<=n;s++){
ans+=dp[n][s];
ans %= mod;
}
out.println(ans);
out.close();
}
public static long inv(long n){
return power(n, mod-2);
}
public static void sort(int[] array){
ArrayList<Integer> copy = new ArrayList<>();
for (int i : array)
copy.add(i);
Collections.sort(copy);
for(int i = 0;i<array.length;i++)
array[i] = copy.get(i);
}
static String[] readArrayString(int n){
String[] array = new String[n];
for(int j =0 ;j<n;j++)
array[j] = sc.next();
return array;
}
static int[] readArrayInt(int n){
int[] array = new int[n];
for(int j = 0;j<n;j++)
array[j] = sc.nextInt();
return array;
}
static int[] readArrayInt1(int n){
int[] array = new int[n+1];
for(int j = 1;j<=n;j++){
array[j] = sc.nextInt();
}
return array;
}
static long[] readArrayLong(int n){
long[] array = new long[n];
for(int j =0 ;j<n;j++)
array[j] = sc.nextLong();
return array;
}
static double[] readArrayDouble(int n){
double[] array = new double[n];
for(int j =0 ;j<n;j++)
array[j] = sc.nextDouble();
return array;
}
static int minIndex(int[] array){
int minValue = Integer.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static int minIndex(long[] array){
long minValue = Long.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static int minIndex(double[] array){
double minValue = Double.MAX_VALUE;
int minIndex = -1;
for(int j = 0;j<array.length;j++){
if (array[j] < minValue){
minValue = array[j];
minIndex = j;
}
}
return minIndex;
}
static long power(long x, long y){
if (y == 0)
return 1;
if (y%2 == 1)
return (x*power(x, y-1))%mod;
return power((x*x)%mod, y/2)%mod;
}
static void verdict(boolean a){
out.println(a ? "YES" : "NO");
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try{
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
//StringJoiner sj = new StringJoiner(" ");
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;
public class CF_2020_GlobalRound_E {
static boolean verb=true;
static void log(Object X){if (verb) System.err.println(X);}
static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}
static InputReader reader;
static long[][] binom;
static void buildBinom(int N){
int MAX=N+1;
binom=new long[MAX+1][];
for (int i=0;i<MAX+1;i++)
binom[i]=new long[i+1];
binom[0][0]=1;
for (int i=1;i<MAX;i++){
binom[i][0]=1;
binom[i][i]=1;
for (int j=0;j<i;j++) {
binom[i+1][j+1]=(binom[i][j]+binom[i][j+1])%mod;
}
//log(binom[i]);
}
log("binom done");
}
static long mod;
static long solve(int n) {
long[] pow2=new long[n+1];
pow2[0]=1;
for (int i=1;i<=n;i++) {
pow2[i]=pow2[i-1]<<1;
while (pow2[i]>=mod)
pow2[i]-=mod;
}
buildBinom(n);
long[][] dp=new long[n+1][n+1];
dp[1][1]=1;
for (int i=1;i<=n;i++) {
dp[i][i]=pow2[i-1];
//log("base:"+dp[i][i]);
for (int j=1;j<i-1;j++){
int me=i-j-1;
for (int cn=1;cn<=j;cn++) {
//log("j:"+j+" cn:"+cn+" dp:"+dp[j][cn]);
//log("perm:"+binom[cn+me][cn]);
long a=dp[j][cn]*binom[cn+me][cn];
if (a>=mod)
a%=mod;
a*=pow2[me-1];
if (a>=mod)
a%=mod;
dp[i][cn+me]+=a;
if (dp[i][cn+me]>=mod)
dp[i][cn+me]-=mod;
}
}
}
long ans=0;
for (int i=n/2;i<=n;i++) {
ans+=dp[n][i];
ans%=mod;
}
return ans;
}
public static void main(String[] args) throws Exception {
log(400*400*400);
reader=new InputReader(System.in);
int n=reader.readInt();
mod=reader.readInt();
System.out.println(solve(n));
}
static final class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int read() throws IOException {
if (curChar >= numChars) {
curChar = 0;
numChars = stream.read(buf);
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public final String readString() throws IOException {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res=new StringBuilder();
do {
res.append((char)c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public final int readInt() throws IOException {
int c = read();
boolean neg=false;
while (isSpaceChar(c)) {
c = read();
}
char d=(char)c;
//log("d:"+d);
if (d=='-') {
neg=true;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
//log("res:"+res);
if (neg)
return -res;
return res;
}
public final long readLong() throws IOException {
int c = read();
boolean neg=false;
while (isSpaceChar(c)) {
c = read();
}
char d=(char)c;
//log("d:"+d);
if (d=='-') {
neg=true;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
//log("res:"+res);
if (neg)
return -res;
return res;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.util.*;
public class Main {
static int m;
static long pow(long b, int p) {
long ret = 1;
while (p > 0) {
if ((p&1) == 1) ret = b*ret%m;
b = b*b%m;
p >>= 1;
}
return ret;
}
public static void main(String[] args) throws IOException {
int n = readInt(); m = readInt();
long[] fac = new long[n + 1], pow2 = new long[n + 1];
long[][] C = new long[n + 1][n + 1], dp = new long[n + 1][n + 1];
fac[0] = pow2[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = i*fac[i - 1]%m;
pow2[i] = 2*pow2[i - 1]%m;
for (int j = 0; j <= i; ++j)
C[i][j] = fac[i]*(pow(fac[j], m - 2)*pow(fac[i - j], m - 2)%m)%m;
}
for (int i = 1; i <= n; ++i) {
dp[i][i] = pow2[i - 1];
for (int j = 0; j <= i; ++j)
for (int k = 1; i + k + 1 <= n; ++k)
dp[i + k + 1][j + k] = (dp[i + k + 1][j + k] + dp[i][j]*(C[j + k][k]*pow2[k - 1]%m))%m;
}
long ans = 0;
for (int i = 1; i <= n; ++i)
ans = (ans + dp[n][i])%m;
System.out.println(ans);
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class e_g14 {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
FastScanner in = new FastScanner(System.in);
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
int T = 1;
Solver A = new Solver(in, out);
for(int aa = 0; aa < T; aa++) {
A.answer(aa + 1);
}
out.close();
}
static class Solver {
FastScanner in;
PrintWriter out;
int n;
long m;
long [] fact, pow, choose [], dp[];
public Solver(FastScanner in, PrintWriter out) {
this.in = in;
this.out = out;
}
public void answer(int aa) throws Exception {
n = in.nextInt();
m = in.nextLong();
fact = new long [n+5];
choose = new long [n+5][n+5];
dp = new long [n+2][n+2];
pow = new long [n+2];
init();
dp[0][0] = 1;
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= i; j++) {
for(int k = 1; i+k <= n; k++) {
dp[i+k+1][j+k] += (dp[i][j]*choose[j+k][k]%m)*pow[k-1];
dp[i+k+1][j+k] %= m;
}
}
}
long ans = 0;
for(int i = 0; i <= n; i++) {
ans += dp[n+1][i];
ans %= m;
}
out.println(ans);
}
public void init() {
fact[0] = 1;
for(int i = 1; i <= n+4; i++) {
fact[i] = (i*fact[i-1])%m;
}
pow[0] = 1;
for(int i = 1; i <= n+1; i++) {
pow[i] = (2*pow[i-1])%m;
}
for(int i = 0; i <= n+4; i++) {
for(int j = 0; j <= i; j++) {
choose[i][j] = choose(i, j);
}
}
}
private long choose(int a, int b) {
long res = (fact[a] * inv((fact[b] * fact[a-b])%m))%m;
return res;
}
private long power (long x, long y) {
long res = 1;
while(y > 0) {
if(y%2 == 1) res = (res*x)%m;
x = (x*x)%m;
y /= 2;
}
return (res%m);
}
private long inv (long a) {
return power(a, m-2);
}
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
st = new StringTokenizer("");
}
public FastScanner(String fileName) throws Exception {
br = new BufferedReader(new FileReader(new File(fileName)));
st = new StringTokenizer("");
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public Double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String nextLine() throws Exception {
if (st.hasMoreTokens()) {
StringBuilder str = new StringBuilder();
boolean first = true;
while (st.hasMoreTokens()) {
if (first) {
first = false;
} else {
str.append(" ");
}
str.append(st.nextToken());
}
return str.toString();
} else {
return br.readLine();
}
}
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.util.*;
public class E {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
readInput();
out.close();
}
static long[][] dp;
static int n;
static long m;
static long pow(long b, long e) {
if (e== 0) return 1;
long r= pow(b,e/2);
r = r * r % m;
if ((e&1)==1) return r *b%m;
return r;
}
static long modinv(long a) {return pow(a,m-2);}
static long solve(int len, int num) {
if (len == -1 && num == -1) return 1;
if (num < 0 || len <= 0) return 0;
if (dp[len][num] == -1) {
dp[len][num] = 0;
for (int i = 0; i < len; i++) {
if (i == 1) continue;
long sol = pow[len-i-1]*solve(i-1,num-1)%m;
sol = sol * faci[len-i]% m;
dp[len][num] += sol;
dp[len][num] %= m;
}
}
return dp[len][num];
}
static long[] fac, faci, pow;
//asdf
public static void readInput() throws IOException {
// br = new BufferedReader(new FileReader(".in"));
// out = new PrintWriter(new FileWriter(".out"));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Long.parseLong(st.nextToken());
fac = new long[500];
pow = new long[500];
faci = new long[fac.length];
fac[0] = pow[0] = 1;
faci[0] = modinv(fac[0]);
for (int i = 1; i < fac.length; i++) {
fac[i] = fac[i-1]*i%m;
faci[i] = modinv(fac[i]);
pow[i] = pow[i-1] * 2 % m;
}
dp = new long[n+1][n+1];
for (long[] a: dp) Arrays.fill(a, -1);
// Number of ways to make a segment of length x is 2^(x-1)
// DP: Given position I.
long ans =0 ;
for (int i = 0 ; i <= n/2+1; i++) {
//System.out.println(i + ": " + solve(n,i) + " " + (n-i) + " " + (i));
long sol = solve(n,i) * fac[n-i];
sol %= m;
ans += sol;
}
out.println(ans%m);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
public class Main {
private static final String NO = "NO";
private static final String YES = "YES";
InputStream is;
PrintWriter out;
String INPUT = "";
private static long MOD = 1000000007;
private static final int MAXN = 100000;
void solve() {
int T = 1;// ni();
for (int i = 0; i < T; i++) {
solve(i);
}
}
static final int N = 405;
static long[][] dp = new long[N][N];
static long[] p2 = new long[N];
static long[] fac = new long[N];
static long[] ifac = new long[N];
public static long bino(int n, int k) {
return ((fac[n] * ifac[n - k]) % MOD * ifac[k]) % MOD;
}
void solve(int T) {
int n = ni();
MOD = nl();
fac[0] = 1;
ifac[0] = 1;
p2[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = (fac[i - 1] * i) % MOD;
p2[i] = (p2[i - 1] * 2) % MOD;
}
ifac[n] = power(fac[n], MOD - 2);
for (int i = n - 1; i > 0; --i) {
ifac[i] = (ifac[i + 1] * (i + 1)) % MOD;
}
dp[0][0] = 1;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= i; ++j) {
for (int k = 1; i + k <= n; ++k) {
dp[i + k + 1][j
+ k] = (dp[i + k + 1][j + k] + ((dp[i][j] * p2[k - 1]) % MOD * bino(k + j, k)) % MOD) % MOD;
}
}
}
long ans = 0;
for (int i = 0; i <= n; ++i) {
ans = (ans + dp[n + 1][i]) % MOD;
}
out.println(ans);
}
// a^b
long power(long a, long b) {
long x = 1, y = a;
while (b > 0) {
if (b % 2 != 0) {
x = (x * y) % MOD;
}
y = (y * y) % MOD;
b /= 2;
}
return x % MOD;
}
private long gcd(long a, long b) {
while (a != 0) {
long tmp = b % a;
b = a;
a = tmp;
}
return b;
}
void run() throws Exception {
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if (!INPUT.isEmpty())
tr(System.currentTimeMillis() - s + "ms");
}
public static void main(String[] args) throws Exception {
new Main().run();
}
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1)
throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b))
;
return b;
}
private double nd() {
return Double.parseDouble(ns());
}
private char nc() {
return (char) skip();
}
private String ns() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != '
// ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n) {
if (!(isSpaceChar(b)))
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for (int i = 0; i < n; i++)
map[i] = ns(m);
return map;
}
private int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = ni();
return a;
}
private List<Integer> na2(int n) {
List<Integer> a = new ArrayList<Integer>();
for (int i = 0; i < n; i++)
a.add(ni());
return a;
}
private int[][] na(int n, int m) {
int[][] a = new int[n][];
for (int i = 0; i < n; i++)
a[i] = na(m);
return a;
}
private int ni() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private long[] nl(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nl();
return a;
}
private long[][] nl(int n, int m) {
long[][] a = new long[n][];
for (int i = 0; i < n; i++)
a[i] = nl(m);
return a;
}
private long nl() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = num * 10 + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) {
System.out.println(Arrays.deepToString(o));
}
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
//package global14;
import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;
public class E2 {
InputStream is;
FastWriter out;
String INPUT = "";
public static int[][] enumFIF(int n, int mod) {
int[] f = new int[n + 1];
int[] invf = new int[n + 1];
f[0] = 1;
for (int i = 1; i <= n; i++) {
f[i] = (int) ((long) f[i - 1] * i % mod);
}
long a = f[n];
long b = mod;
long p = 1, q = 0;
while (b > 0) {
long c = a / b;
long d;
d = a;
a = b;
b = d % b;
d = p;
p = q;
q = d - c * q;
}
invf[n] = (int) (p < 0 ? p + mod : p);
for (int i = n - 1; i >= 0; i--) {
invf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);
}
return new int[][]{f, invf};
}
public static long[] enumPows(int a, int n, int mod)
{
a %= mod;
long[] pows = new long[n+1];
pows[0] = 1;
for(int i = 1;i <= n;i++)pows[i] = pows[i-1] * a % mod;
return pows;
}
void solve()
{
int N = ni();
final int mod = ni();
long[] p2 = enumPows(2, 1000, mod);
int[][] fif = enumFIF(1000, mod);
long[][] dp = new long[N+2][N+1];
dp[0][0] = 1;
for(int i = 0;i <= N+1;i++){
for(int j = 0;j <= N;j++){
// 11110
for(int k = 1;i+k+1 <= N+1 && j+k <= N;k++){
dp[i+k+1][j+k] += dp[i][j] * fif[1][k] % mod * p2[k-1];
dp[i+k+1][j+k] %= mod;
}
}
// tr(dp[i]);
}
long ans = 0;
for(int i = 1;i <= N;i++){
ans += dp[N+1][i] * fif[0][i];
ans %= mod;
}
out.println(ans);
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new FastWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new E2().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private long[] nal(int n)
{
long[] a = new long[n];
for(int i = 0;i < n;i++)a[i] = nl();
return a;
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[][] nmi(int n, int m) {
int[][] map = new int[n][];
for(int i = 0;i < n;i++)map[i] = na(m);
return map;
}
private int ni() { return (int)nl(); }
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
public static class FastWriter
{
private static final int BUF_SIZE = 1<<13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter(){out = null;}
public FastWriter(OutputStream os)
{
this.out = os;
}
public FastWriter(String path)
{
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b)
{
buf[ptr++] = b;
if(ptr == BUF_SIZE)innerflush();
return this;
}
public FastWriter write(char c)
{
return write((byte)c);
}
public FastWriter write(char[] s)
{
for(char c : s){
buf[ptr++] = (byte)c;
if(ptr == BUF_SIZE)innerflush();
}
return this;
}
public FastWriter write(String s)
{
s.chars().forEach(c -> {
buf[ptr++] = (byte)c;
if(ptr == BUF_SIZE)innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000) return 10;
if (l >= 100000000) return 9;
if (l >= 10000000) return 8;
if (l >= 1000000) return 7;
if (l >= 100000) return 6;
if (l >= 10000) return 5;
if (l >= 1000) return 4;
if (l >= 100) return 3;
if (l >= 10) return 2;
return 1;
}
public FastWriter write(int x)
{
if(x == Integer.MIN_VALUE){
return write((long)x);
}
if(ptr + 12 >= BUF_SIZE)innerflush();
if(x < 0){
write((byte)'-');
x = -x;
}
int d = countDigits(x);
for(int i = ptr + d - 1;i >= ptr;i--){
buf[i] = (byte)('0'+x%10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public FastWriter write(long x)
{
if(x == Long.MIN_VALUE){
return write("" + x);
}
if(ptr + 21 >= BUF_SIZE)innerflush();
if(x < 0){
write((byte)'-');
x = -x;
}
int d = countDigits(x);
for(int i = ptr + d - 1;i >= ptr;i--){
buf[i] = (byte)('0'+x%10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision)
{
if(x < 0){
write('-');
x = -x;
}
x += Math.pow(10, -precision)/2;
// if(x < 0){ x = 0; }
write((long)x).write(".");
x -= (long)x;
for(int i = 0;i < precision;i++){
x *= 10;
write((char)('0'+(int)x));
x -= (int)x;
}
return this;
}
public FastWriter writeln(char c){
return write(c).writeln();
}
public FastWriter writeln(int x){
return write(x).writeln();
}
public FastWriter writeln(long x){
return write(x).writeln();
}
public FastWriter writeln(double x, int precision){
return write(x, precision).writeln();
}
public FastWriter write(int... xs)
{
boolean first = true;
for(int x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs)
{
boolean first = true;
for(long x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln()
{
return write((byte)'\n');
}
public FastWriter writeln(int... xs)
{
return write(xs).writeln();
}
public FastWriter writeln(long... xs)
{
return write(xs).writeln();
}
public FastWriter writeln(char[] line)
{
return write(line).writeln();
}
public FastWriter writeln(char[]... map)
{
for(char[] line : map)write(line).writeln();
return this;
}
public FastWriter writeln(String s)
{
return write(s).writeln();
}
private void innerflush()
{
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush()
{
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) { return write(b); }
public FastWriter print(char c) { return write(c); }
public FastWriter print(char[] s) { return write(s); }
public FastWriter print(String s) { return write(s); }
public FastWriter print(int x) { return write(x); }
public FastWriter print(long x) { return write(x); }
public FastWriter print(double x, int precision) { return write(x, precision); }
public FastWriter println(char c){ return writeln(c); }
public FastWriter println(int x){ return writeln(x); }
public FastWriter println(long x){ return writeln(x); }
public FastWriter println(double x, int precision){ return writeln(x, precision); }
public FastWriter print(int... xs) { return write(xs); }
public FastWriter print(long... xs) { return write(xs); }
public FastWriter println(int... xs) { return writeln(xs); }
public FastWriter println(long... xs) { return writeln(xs); }
public FastWriter println(char[] line) { return writeln(line); }
public FastWriter println(char[]... map) { return writeln(map); }
public FastWriter println(String s) { return writeln(s); }
public FastWriter println() { return writeln(); }
}
public void trnz(int... o)
{
for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
System.out.println();
}
// print ids which are 1
public void trt(long... o)
{
Queue<Integer> stands = new ArrayDeque<>();
for(int i = 0;i < o.length;i++){
for(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));
}
System.out.println(stands);
}
public void tf(boolean... r)
{
for(boolean x : r)System.out.print(x?'#':'.');
System.out.println();
}
public void tf(boolean[]... b)
{
for(boolean[] r : b) {
for(boolean x : r)System.out.print(x?'#':'.');
System.out.println();
}
System.out.println();
}
public void tf(long[]... b)
{
if(INPUT.length() != 0) {
for (long[] r : b) {
for (long x : r) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
System.out.println();
}
}
public void tf(long... b)
{
if(INPUT.length() != 0) {
for (long x : b) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;
public class CF_2020_GlobalRound_E {
static boolean verb=true;
static void log(Object X){if (verb) System.err.println(X);}
static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
static void log(int[] X,int L){if (verb) {for (int i=0;i<L;i++) System.err.print(X[i]+" ");System.err.println("");}}
static void log(long[] X){if (verb) {for (long U:X) System.err.print(U+" ");System.err.println("");}}
static InputReader reader;
static long[][] binom;
static void buildBinom(int N){
int MAX=N+1;
binom=new long[MAX+1][];
for (int i=0;i<MAX+1;i++)
binom[i]=new long[i+1];
binom[0][0]=1;
for (int i=1;i<MAX;i++){
binom[i][0]=1;
binom[i][i]=1;
for (int j=0;j<i;j++) {
binom[i+1][j+1]=(binom[i][j]+binom[i][j+1])%mod;
}
//log(binom[i]);
}
log("binom done");
}
static long mod;
static long solve(int n) {
long[] pow2=new long[n+1];
pow2[0]=1;
for (int i=1;i<=n;i++) {
pow2[i]=pow2[i-1]<<1;
while (pow2[i]>=mod)
pow2[i]-=mod;
}
buildBinom(n);
long[][] dp=new long[n+1][n+1];
dp[1][1]=1;
for (int i=1;i<=n;i++) {
dp[i][i]=pow2[i-1];
//log("base:"+dp[i][i]);
for (int j=1;j<i-1;j++){
int me=i-j-1;
for (int cn=1;cn<=j;cn++) {
//log("j:"+j+" cn:"+cn+" dp:"+dp[j][cn]);
//log("perm:"+binom[cn+me][cn]);
dp[i][cn+me]+=(((dp[j][cn]*binom[cn+me][cn])%mod)*pow2[me-1])%mod;
dp[i][cn+me]%=mod;
}
}
}
long ans=0;
for (int i=0;i<=n;i++) {
ans+=dp[n][i];
ans%=mod;
}
return ans;
}
public static void main(String[] args) throws Exception {
log(400*400*400);
reader=new InputReader(System.in);
int n=reader.readInt();
mod=reader.readInt();
System.out.println(solve(n));
}
static final class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
private int read() throws IOException {
if (curChar >= numChars) {
curChar = 0;
numChars = stream.read(buf);
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public final String readString() throws IOException {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res=new StringBuilder();
do {
res.append((char)c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public final int readInt() throws IOException {
int c = read();
boolean neg=false;
while (isSpaceChar(c)) {
c = read();
}
char d=(char)c;
//log("d:"+d);
if (d=='-') {
neg=true;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
//log("res:"+res);
if (neg)
return -res;
return res;
}
public final long readLong() throws IOException {
int c = read();
boolean neg=false;
while (isSpaceChar(c)) {
c = read();
}
char d=(char)c;
//log("d:"+d);
if (d=='-') {
neg=true;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
//log("res:"+res);
if (neg)
return -res;
return res;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
public class Main{
static long MOD = 1_000_000_007L;
//static long MOD = 998_244_353L;
//static long MOD = 1_000_000_033L;
static long inv2 = (MOD + 1) / 2;
static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
static long lMax = 0x3f3f3f3f3f3f3f3fL;
static int iMax = 0x3f3f3f3f;
static HashMap <Long, Long> memo = new HashMap();
static MyScanner sc = new MyScanner();
//static ArrayList <Integer> primes;
static int nn = 300000;
static long[] pow2;
static long [] fac;
static long [] pow;
static long [] inv;
static long [] facInv;
static int[] base;
static int[] numOfDiffDiv;
static int[] numOfDiv;
static ArrayList <Integer> primes;
//static int[] primes;
static int ptr = 0;
static boolean[] isPrime;
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
public static void main(String[] args) {
out = new PrintWriter(new BufferedOutputStream(System.out));
// Start writing your solution here. -------------------------------------
/*fac = new long[nn + 1];
fac[1] = 1;
for(int i = 2; i <= nn; i++)
fac[i] = fac[i - 1] * i % MOD;*/
/*pow2 = new long[nn + 1];
pow2[0] = 1L;
for(int i = 1; i <= nn; i++)
pow2[i] = pow2[i - 1] * 2L;*/
/*inv = new long[nn + 1];
inv[1] = 1;
for (int i = 2; i <= nn; ++i)
inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/
/*facInv = new long[nn + 1];
facInv[0] = facInv[1] = 1;
for (int i = 2; i <= nn; ++i)
facInv[i] = facInv[i - 1] * inv[i] % MOD;*/
/*numOfDiffDiv = new int[nn + 1];
for(int i = 2; i <= nn; i++)
if(numOfDiffDiv[i] == 0)
for(int j = i; j <= nn; j += i)
numOfDiv[j] ++;*/
/*numOfDiv = new int[nn + 1];
numOfDiv[1] = 1;
for(int i = 2; i <= nn; i++) {
for(int j = 2; j * j <= i; j++) {
if(i % j == 0) {
numOfDiv[i] = numOfDiv[i / j] + 1;
break;
}
}
}*/
//primes = sieveOfEratosthenes(100001);
/*
int t = 1;
//t = sc.ni();
while(t-- > 0) {
//boolean res = solve();
//out.println(res ? "YES" : "NO");
long res = solve();
out.println(res);
}*/
int t = 1, tt = 0;
//t = sc.ni();
for(int i = 1; i <40000; i++) squares.add(i * i);
while(tt++ < t) {
boolean res = solve();
//out.println("Case #" + tt + ": " + res);
//out.println(res ? "YES" : "NO");
}
out.close();
}
static HashSet <Integer> squares = new HashSet();
static boolean solve() {
/*String s = sc.nextLine();
char[] c = s.toCharArray();
int n = c.length;*/
//int n = sc.ni();
//long[] a = new long[n];
//for(int i = 0; i < n; i++) a[i] = sc.nl();
long res = 0;
int n = sc.ni();
long m = sc.nl();
long[][][] dp = new long[2][n + 3][n + 3];
long[][][] dp2 = new long[2][n + 3][n + 3];
dp[0][2][1] = dp[1][2][2] = dp2[0][1][1] = 1L;
for(int i = 3; i <= n; i++) {
long[][] bef = dp[0];
long[][] aft = dp[1];
long[][] nbef = new long[n + 3][n + 3];
long[][] naft = new long[n + 3][n + 3];
for(int len = 1; len <= i; len++) {
for(int ind = 1; ind <= len; ind++) {
nbef[len + 1][1] += bef[len][ind];
nbef[len + 1][ind + 1] -= bef[len][ind];
naft[len + 1][ind + 1] += bef[len][ind];
//naft[len + 1][len + 2] -= bef[len][ind];
naft[len + 1][ind + 1] += aft[len][ind];
//naft[len + 1][len + 2] -= aft[len][ind];
nbef[len + 1][1] += dp2[0][len][ind] + dp2[1][len][ind];
//nbef[len + 1][len + 2] -= dp2[0][len][ind] + dp2[1][len][ind];
}
}
for(int len = 1; len <= i; len++) {
for(int ind = 1; ind <= len; ind ++) {
nbef[len][ind] = (nbef[len][ind] + nbef[len][ind - 1] + 10000000L * m) % m;
naft[len][ind] = (naft[len][ind] + naft[len][ind - 1] + 10000000L * m) % m;
}
}
dp2 = dp;
dp = new long[][][]{nbef, naft};
}
for(long[] row: dp[0])
for(long i : row)
res += i;
for(long[] row: dp[1])
for(long i : row)
res += i;
out.println(res % m);
return false;
}
// edges to adjacency list by uwi
public static int[][] packU(int n, int[] from, int[] to) {
return packU(n, from, to, from.length);
}
public static int[][] packU(int n, int[] from, int[] to, int sup) {
int[][] g = new int[n][];
int[] p = new int[n];
for (int i = 0; i < sup; i++) p[from[i]]++;
for (int i = 0; i < sup; i++) p[to[i]]++;
for (int i = 0; i < n; i++) g[i] = new int[p[i]];
for (int i = 0; i < sup; i++) {
g[from[i]][--p[from[i]]] = to[i];
g[to[i]][--p[to[i]]] = from[i];
}
return g;
}
// tree diameter by uwi
public static int[] diameter(int[][] g) {
int n = g.length;
int f0 = -1, f1 = -1, d01 = -1;
int[] q = new int[n];
boolean[] ved = new boolean[n];
{
int qp = 0;
q[qp++] = 0; ved[0] = true;
for(int i = 0;i < qp;i++){
int cur = q[i];
for(int e : g[cur]){
if(!ved[e]){
ved[e] = true;
q[qp++] = e;
continue;
}
}
}
f0 = q[n-1];
}
{
int[] d = new int[n];
int qp = 0;
Arrays.fill(ved, false);
q[qp++] = f0; ved[f0] = true;
for(int i = 0;i < qp;i++){
int cur = q[i];
for(int e : g[cur]){
if(!ved[e]){
ved[e] = true;
q[qp++] = e;
d[e] = d[cur] + 1;
continue;
}
}
}
f1 = q[n-1];
d01 = d[f1];
}
return new int[]{d01, f0, f1};
}
public static long c(int n, int k) {
return (fac[n] * facInv[k] % MOD) * facInv[n - k] % MOD;
}
// SegmentTree range min/max query by uwi
public static class SegmentTreeRMQ {
public int M, H, N;
public int[] st;
public SegmentTreeRMQ(int n)
{
N = n;
M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
H = M>>>1;
st = new int[M];
Arrays.fill(st, 0, M, Integer.MAX_VALUE);
}
public SegmentTreeRMQ(int[] a)
{
N = a.length;
M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
H = M>>>1;
st = new int[M];
for(int i = 0;i < N;i++){
st[H+i] = a[i];
}
Arrays.fill(st, H+N, M, Integer.MAX_VALUE);
for(int i = H-1;i >= 1;i--)propagate(i);
}
public void update(int pos, int x)
{
st[H+pos] = x;
for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);
}
private void propagate(int i)
{
st[i] = Math.min(st[2*i], st[2*i+1]);
}
public int minx(int l, int r){
int min = Integer.MAX_VALUE;
if(l >= r)return min;
while(l != 0){
int f = l&-l;
if(l+f > r)break;
int v = st[(H+l)/f];
if(v < min)min = v;
l += f;
}
while(l < r){
int f = r&-r;
int v = st[(H+r)/f-1];
if(v < min)min = v;
r -= f;
}
return min;
}
public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}
private int min(int l, int r, int cl, int cr, int cur)
{
if(l <= cl && cr <= r){
return st[cur];
}else{
int mid = cl+cr>>>1;
int ret = Integer.MAX_VALUE;
if(cl < r && l < mid){
ret = Math.min(ret, min(l, r, cl, mid, 2*cur));
}
if(mid < r && l < cr){
ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));
}
return ret;
}
}
}
public static char[] rev(char[] a){char[] b = new char[a.length];for(int i = 0;i < a.length;i++)b[a.length-1-i] = a[i];return b;}
public static double dist(double a, double b){
return Math.sqrt(a * a + b * b);
}
public static long inv(long a){
return quickPOW(a, MOD - 2);
}
public class Interval {
int start;
int end;
public Interval(int start, int end) {
this.start = start;
this.end = end;
}
}
public static ArrayList<Integer> sieveOfEratosthenes(int n) {
boolean prime[] = new boolean[n + 1];
Arrays.fill(prime, true);
for (int p = 2; p * p <= n; p++) {
if (prime[p]) {
for (int i = p * 2; i <= n; i += p) {
prime[i] = false;
}
}
}
ArrayList<Integer> primeNumbers = new ArrayList<>();
for (int i = 2; i <= n; i++) {
if (prime[i]) {
primeNumbers.add(i);
}
}
return primeNumbers;
}
public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
public static int lowerBound(int[] a, int l, int r, int v)
{
if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
int low = l-1, high = r;
while(high-low > 1){
int h = high+low>>>1;
if(a[h] >= v){
high = h;
}else{
low = h;
}
}
return high;
}
public static int rlowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
public static int rlowerBound(int[] a, int l, int r, int v)
{
if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
int low = l-1, high = r;
while(high-low > 1){
int h = high+low>>>1;
if(a[h] <= v){
high = h;
}else{
low = h;
}
}
return high;
}
public static long C(int n, int m)
{
if(m == 0 || m == n) return 1l;
if(m > n || m < 0) return 0l;
long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;
return res;
}
public static long quickPOW(long n, long m)
{
long ans = 1l;
while(m > 0)
{
if(m % 2 == 1)
ans = (ans * n) % MOD;
n = (n * n) % MOD;
m >>= 1;
}
return ans;
}
public static long quickPOW(long n, long m, long mod)
{
long ans = 1l;
while(m > 0)
{
if(m % 2 == 1)
ans = (ans * n) % mod;
n = (n * n) % mod;
m >>= 1;
}
return ans;
}
public static int gcd(int a, int b)
{
if(a % b == 0) return b;
return gcd(b, a % b);
}
public static long gcd(long a, long b)
{
if(a % b == 0) return b;
return gcd(b, a % b);
}
static class Randomized {
public static void shuffle(int[] data) {
shuffle(data, 0, data.length - 1);
}
public static void shuffle(int[] data, int from, int to) {
to--;
for (int i = from; i <= to; i++) {
int s = nextInt(i, to);
int tmp = data[i];
data[i] = data[s];
data[s] = tmp;
}
}
public static void shuffle(long[] data) {
shuffle(data, 0, data.length - 1);
}
public static void shuffle(long[] data, int from, int to) {
to--;
for (int i = from; i <= to; i++) {
int s = nextInt(i, to);
long tmp = data[i];
data[i] = data[s];
data[s] = tmp;
}
}
public static int nextInt(int l, int r) {
return RandomWrapper.INSTANCE.nextInt(l, r);
}
}
static class RandomWrapper {
private Random random;
public static final RandomWrapper INSTANCE = new RandomWrapper(new Random());
public RandomWrapper() {
this(new Random());
}
public RandomWrapper(Random random) {
this.random = random;
}
public int nextInt(int l, int r) {
return random.nextInt(r - l + 1) + l;
}
}
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | cubic | 1515_E. Phoenix and Computers | CODEFORCES |
import java.io.*;
import java.util.*;
public class E {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
public static void main(String[] args) throws IOException {
readInput();
out.close();
}
static long[][] dp;
static int n;
static long m;
static long pow(long b, long e) {
if (e== 0) return 1;
long r= pow(b,e/2);
r = r * r % m;
if ((e&1)==1) return r *b%m;
return r;
}
static long modinv(long a) {return pow(a,m-2);}
static long solve(int len, int num) {
if (len == -1 && num == -1) return 1;
if (num < 0 || len <= 0) return 0;
if (dp[len][num] == -1) {
dp[len][num] = 0;
for (int i = 0; i < len; i++) {
if (i == 1) continue;
long sol = pow[len-i-1]*solve(i-1,num-1)%m;
sol = sol * faci[len-i]% m;
dp[len][num] += sol;
dp[len][num] %= m;
}
}
return dp[len][num];
}
static long[] fac, faci, pow;
public static void readInput() throws IOException {
// br = new BufferedReader(new FileReader(".in"));
// out = new PrintWriter(new FileWriter(".out"));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
m = Long.parseLong(st.nextToken());
fac = new long[500];
pow = new long[500];
faci = new long[fac.length];
fac[0] = pow[0] = 1;
faci[0] = modinv(fac[0]);
for (int i = 1; i < fac.length; i++) {
fac[i] = fac[i-1]*i%m;
faci[i] = modinv(fac[i]);
pow[i] = pow[i-1] * 2 % m;
}
dp = new long[n+1][n+1];
for (long[] a: dp) Arrays.fill(a, -1);
// Number of ways to make a segment of length x is 2^(x-1)
// DP: Given position I.
long ans =0 ;
for (int i = 0 ; i <= n/2+1; i++) {
//System.out.println(i + ": " + solve(n,i) + " " + (n-i) + " " + (i));
long sol = solve(n,i) * fac[n-i];
sol %= m;
ans += sol;
}
out.println(ans%m);
}
}
| cubic | 1515_E. Phoenix and Computers | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, dd, bb;
int[] uu, vv, uv, cost;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
dd = new int[n_];
bb = new int[n_];
qq = new int[nq];
iq = new boolean[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
int[] qq;
int nq = 1, head, cnt;
boolean[] iq;
void enqueue(int v) {
if (iq[v])
return;
if (head + cnt == nq) {
if (cnt * 2 <= nq)
System.arraycopy(qq, head, qq, 0, cnt);
else {
int[] qq_ = new int[nq *= 2];
System.arraycopy(qq, head, qq_, 0, cnt);
qq = qq_;
}
head = 0;
}
qq[head + cnt++] = v; iq[v] = true;
}
int dequeue() {
int u = qq[head++]; cnt--; iq[u] = false;
return u;
}
boolean spfa(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
head = cnt = 0;
enqueue(s);
while (cnt > 0) {
int u = dequeue();
int d = dd[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && dd[v] > d) {
pi[v] = p;
dd[v] = d;
bb[v] = h_;
enqueue(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
while (spfa(s, t))
push1(s, t);
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
//package com.company;
import java.io.*;
import java.util.*;
public class Main {
public static class Task {
public class Maxflow {
class Edge {
int t, rev;
long cap, f;
public Edge(int t, int rev, long cap) {
this.t = t;
this.rev = rev;
this.cap = cap;
}
}
public Maxflow(int n) {
graph = new List[n];
for (int i = 0; i < n; i++) {
graph[i] = new ArrayList<>();
}
}
List<Edge>[] graph;
void addEdge(int s, int t, long cap) {
graph[s].add(new Edge(t, graph[t].size(), cap));
graph[t].add(new Edge(s, graph[s].size() - 1, 0));
// System.err.println(s + " " + t + " " + cap);
}
boolean dinicBFS(int src, int dest, int[] dist) {
Arrays.fill(dist, -1);
dist[src] = 0;
int[] Q = new int[graph.length];
int sizeQ = 0;
Q[sizeQ++] = src;
for (int i = 0; i < sizeQ; i++) {
int u = Q[i];
for (Edge e: graph[u]) {
if (dist[e.t] < 0 && e.f < e.cap) {
dist[e.t] = dist[u] + 1;
Q[sizeQ++] = e.t;
}
}
}
return dist[dest] >= 0;
}
long dinicDFS(int[] ptr, int[] dist, int dest, int u, long f) {
if (u == dest) return f;
for (;ptr[u] < graph[u].size(); ++ptr[u]) {
Edge e = graph[u].get(ptr[u]);
if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
long df = dinicDFS(ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));
if (df > 0) {
e.f += df;
graph[e.t].get(e.rev).f -= df;
return df;
}
}
}
return 0;
}
long maxFLow(int src, int dest) {
long flow = 0;
int[] dist = new int[graph.length];
while (dinicBFS(src, dest, dist)) {
int[] ptr = new int[graph.length];
while (true) {
long df = dinicDFS(ptr, dist, dest, src, Long.MAX_VALUE);
if (df == 0) break;
flow += df;
}
}
return flow;
}
}
public class MinCostFlowBF {
List<Edge>[] graph;
class Edge {
int to, f, cap, cost, rev;
Edge(int v, int cap, int cost, int rev) {
this.to = v;
this.cap = cap;
this.cost = cost;
this.rev = rev;
}
}
public MinCostFlowBF(int n) {
graph = new List[n];
for (int i = 0; i < n; i++)
graph[i] = new ArrayList<Edge>();
}
public void addEdge(int s, int t, int cap, int cost) {
graph[s].add(new Edge(t, cap, cost, graph[t].size()));
graph[t].add(new Edge(s, 0, -cost, graph[s].size() - 1));
}
void bellmanFord(int s, int[] dist, int[] prevnode, int[] prevedge, int[] curflow) {
int n = graph.length;
Arrays.fill(dist, 0, n, Integer.MAX_VALUE);
dist[s] = 0;
curflow[s] = Integer.MAX_VALUE;
boolean[] inqueue = new boolean[n];
int[] q = new int[n];
int qt = 0;
q[qt++] = s;
for (int qh = 0; (qh - qt) % n != 0; qh++) {
int u = q[qh % n];
inqueue[u] = false;
for (int i = 0; i < graph[u].size(); i++) {
Edge e = graph[u].get(i);
if (e.f >= e.cap)
continue;
int v = e.to;
int ndist = dist[u] + e.cost;
if (dist[v] > ndist) {
dist[v] = ndist;
prevnode[v] = u;
prevedge[v] = i;
curflow[v] = Math.min(curflow[u], e.cap - e.f);
if (!inqueue[v]) {
inqueue[v] = true;
q[qt++ % n] = v;
}
}
}
}
}
public int[] minCostFlow(int s, int t, int maxf) {
int n = graph.length;
int[] dist = new int[n];
int[] curflow = new int[n];
int[] prevedge = new int[n];
int[] prevnode = new int[n];
int flow = 0;
int flowCost = 0;
while (flow < maxf) {
bellmanFord(s, dist, prevnode, prevedge, curflow);
if (dist[t] == Integer.MAX_VALUE)
break;
int df = Math.min(curflow[t], maxf - flow);
flow += df;
for (int v = t; v != s; v = prevnode[v]) {
Edge e = graph[prevnode[v]].get(prevedge[v]);
e.f += df;
graph[v].get(e.rev).f -= df;
flowCost += df * e.cost;
}
}
return new int[]{flow, flowCost};
}
}
public void solve(Scanner sc, PrintWriter pw) throws IOException {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] pos = new int[n];
for (int i = 0; i < k; i++) {
pos[sc.nextInt() - 1]++;
}
int T = 100;
MinCostFlowBF mf = new MinCostFlowBF((T + 1) * n + 2);
for (int i = 0; i < n; i++) {
if (pos[i] > 0)
mf.addEdge(0, i + 1, pos[i], 0);
}
for (int i = 0; i < T; i++) {
for (int j = 0; j < n; j++) {
mf.addEdge(1 + i * n + j, 1 + (i + 1) * n + j, k, 0);
}
}
for (int i = 0; i <= T; i++) {
for (int j = 1; j <= k; j++) {
mf.addEdge(1 + i * n, (T + 1) * n + 1, 1, c * i);
}
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
for (int j = 0; j < T; j++) {
int cost = 0;
for (int l = 1; l <= k; l++) {
mf.addEdge(1 + j * n + a, 1 + (j + 1) * n + b, 1, l * l * d - cost);
mf.addEdge(1 + j * n + b, 1 + (j + 1) * n + a, 1, l * l * d - cost);
cost = l * l * d;
}
}
}
int[] flowAndCost = mf.minCostFlow(0, (T + 1) * n + 1, k);
System.err.println(flowAndCost[0]);
pw.println(flowAndCost[1]);
}
}
static long TIME_START, TIME_END;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new FileInputStream("input"));
PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
// PrintWriter pw = new PrintWriter(new FileOutputStream("output"));
Runtime runtime = Runtime.getRuntime();
long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
TIME_START = System.currentTimeMillis();
Task t = new Task();
t.solve(sc, pw);
TIME_END = System.currentTimeMillis();
long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
pw.close();
System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader s) throws FileNotFoundException {
br = new BufferedReader(s);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, kk, bb;
int[] uu, vv, uv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
kk = new int[n_];
bb = new int[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cost_ = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
void dijkstra(int s) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int k = kk[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && kk[v] > k) {
if (pi[v] < INF)
pq.remove(v);
pi[v] = p;
kk[v] = k;
bb[v] = h_;
pq.add(v);
}
}
}
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
System.arraycopy(cost, 0, cost_, 0, m_);
while (true) {
dijkstra(s);
if (pi[t] == INF)
break;
push(s, t);
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
import java.util.*;
import java.io.*;
public class GG {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int N = scanner.nextInt();
int M = scanner.nextInt();
int K = scanner.nextInt();
int C = scanner.nextInt();
int D = scanner.nextInt();
MinCostMaxFlowSolver solver = new EdmondsKarp();
int[] people = new int[K];
for(int i = 0; i < K; i++) people[i] = scanner.nextInt()-1;
Node src = solver.addNode();
Node snk = solver.addNode();
int amt = 350;
Node[][] timeNodes = new Node[N][amt];
for(int i = 0; i < N; i++) {
for(int j = 1; j < amt; j++) {
timeNodes[i][j] = solver.addNode();
if (j > 1) solver.link(timeNodes[i][j-1], timeNodes[i][j], Integer.MAX_VALUE, 0);
}
}
for(int i = 0; i < K; i++) {
solver.link(src, timeNodes[people[i]][1], 1, 0);
}
for(int i = 1; i < amt; i++) {
for(int j = 0; j < K; j++) {
solver.link(timeNodes[0][i], snk, 1, C*i-C);
}
}
for(int i =0; i < M; i++) {
int a = scanner.nextInt()-1;
int b = scanner.nextInt()-1;
for(int j = 1; j < amt-1; j++) {
int prev = 0;
for(int k = 1; k <= K; k++) {
solver.link(timeNodes[a][j], timeNodes[b][j + 1], 1, D*k*k- prev);
solver.link(timeNodes[b][j], timeNodes[a][j + 1], 1, D*k*k - prev);
prev = D * k * k;
}
}
}
long[] ret = solver.getMinCostMaxFlow(src, snk);
out.println(ret[1]);
out.flush();
}
public static class Node {
// thou shall not create nodes except through addNode()
private Node() { }
List<Edge> edges = new ArrayList<Edge>();
int index; // index in nodes array
}
public static class Edge
{
boolean forward; // true: edge is in original graph
Node from, to; // nodes connected
long flow; // current flow
final long capacity;
Edge dual; // reference to this edge's dual
long cost; // only used for MinCost.
protected Edge(Node s, Node d, long c, boolean f)
{
forward = f;
from = s;
to = d;
capacity = c;
}
long remaining() { return capacity - flow; }
void addFlow(long amount) {
flow += amount;
dual.flow -= amount;
}
}
public static abstract class MaxFlowSolver {
List<Node> nodes = new ArrayList<Node>();
public void link(Node n1, Node n2, long capacity) {
link(n1, n2, capacity, 1);
}
public void link(Node n1, Node n2, long capacity, long cost) {
Edge e12 = new Edge(n1, n2, capacity, true);
Edge e21 = new Edge(n2, n1, 0, false);
e12.dual = e21;
e21.dual = e12;
n1.edges.add(e12);
n2.edges.add(e21);
e12.cost = cost;
e21.cost = -cost;
}
void link(int n1, int n2, long capacity) {
link(nodes.get(n1), nodes.get(n2), capacity);
}
protected MaxFlowSolver(int n) {
for (int i = 0; i < n; i++)
addNode();
}
protected MaxFlowSolver() {
this(0);
}
public abstract long getMaxFlow(Node src, Node snk);
public Node addNode() {
Node n = new Node();
n.index = nodes.size();
nodes.add(n);
return n;
}
}
static abstract class MinCostMaxFlowSolver extends MaxFlowSolver {
// returns [maxflow, mincost]
abstract long [] getMinCostMaxFlow(Node src, Node snk);
// unavoidable boiler plate
MinCostMaxFlowSolver () { this(0); }
MinCostMaxFlowSolver (int n) { super(n); }
}
static class EdmondsKarp extends MinCostMaxFlowSolver
{
EdmondsKarp () { this(0); }
EdmondsKarp (int n) { super(n); }
long minCost;
@Override
public long [] getMinCostMaxFlow(Node src, Node snk) {
long maxflow = getMaxFlow(src, snk);
return new long [] { maxflow, minCost };
}
static final long INF = Long.MAX_VALUE/4;
@Override
public long getMaxFlow(Node src, Node snk) {
final int n = nodes.size();
final int source = src.index;
final int sink = snk.index;
long flow = 0;
long cost = 0;
long[] potential = new long[n]; // allows Dijkstra to work with negative edge weights
while (true) {
Edge[] parent = new Edge[n]; // used to store an augmenting path
long[] dist = new long[n]; // minimal cost to vertex
Arrays.fill(dist, INF);
dist[source] = 0;
PriorityQueue<Item> que = new PriorityQueue<Item>();
que.add(new Item(0, source));
while (!que.isEmpty()) {
Item item = que.poll();
if (item.dist != dist[item.v])
continue;
for (Edge e : nodes.get(item.v).edges) {
long temp = dist[item.v] + e.cost + potential[item.v] - potential[e.to.index];
if (e.capacity > e.flow && dist[e.to.index] > temp) {
dist[e.to.index] = temp;
parent[e.to.index] = e;
que.add(new Item(temp, e.to.index));
}
}
}
if (parent[sink] == null)
break;
for (int i = 0; i < n; i++)
if (parent[i] != null)
potential[i] += dist[i];
long augFlow = Long.MAX_VALUE;
for (int i = sink; i != source; i = parent[i].from.index)
augFlow = Math.min(augFlow, parent[i].capacity - parent[i].flow);
for (int i = sink; i != source; i = parent[i].from.index) {
Edge e = parent[i];
e.addFlow(augFlow);
cost += augFlow * e.cost;
}
flow += augFlow;
}
minCost = cost;
return flow;
}
static class Item implements Comparable<Item> {
long dist;
int v;
public Item(long dist, int v) {
this.dist = dist;
this.v = v;
}
public int compareTo(Item that) {
return Long.compare(this.dist, that.dist);
}
}
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner() {
this(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String readNextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readIntArray(int n) {
int[] a = new int[n];
for (int idx = 0; idx < n; idx++) {
a[idx] = nextInt();
}
return a;
}
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
//package educational.round67;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
public class G {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), m = ni(), K = ni(), C = ni(), D = ni();
int[] a = na(K);
int[] from = new int[m];
int[] to = new int[m];
for (int i = 0; i < m; i++) {
from[i] = ni() - 1;
to[i] = ni() - 1;
}
int[][] g = packU(n, from, to);
List<Edge> es = new ArrayList<>();
int time = 100;
for(int i = 0;i < n;i++){
for(int j = 0;j < time-1;j++){
es.add(new Edge(i*time+j, i*time+j+1, 99, C));
}
}
for(int i = 0;i < n;i++){
for(int e : g[i]){
for(int j = 0;j < time-1;j++){
for(int k = 0;k < n;k++){
es.add(new Edge(i*time+j, e*time+j+1, 1, C+D*(2*k+1)));
}
}
}
}
int src = time*n, sink = src+1;
for(int i = 0;i < K;i++){
es.add(new Edge(src, (a[i]-1)*time+0, 1, 0));
}
for(int i = 0;i < time;i++){
es.add(new Edge(0*time+i, sink, 99, 0));
}
out.println(solveMinCostFlowWithSPFA(compileWD(sink+1, es), src, sink, 99));
}
public static class Edge
{
public int from, to;
public int capacity;
public int cost;
public int flow;
public Edge complement;
// public int iniflow;
public Edge(int from, int to, int capacity, int cost) {
this.from = from;
this.to = to;
this.capacity = capacity;
this.cost = cost;
}
}
public static Edge[][] compileWD(int n, List<Edge> edges)
{
Edge[][] g = new Edge[n][];
// cloning
for(int i = edges.size()-1;i >= 0;i--){
Edge origin = edges.get(i);
Edge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);
clone.flow = origin.capacity;
clone.complement = origin;
origin.complement = clone;
edges.add(clone);
}
int[] p = new int[n];
for(Edge e : edges)p[e.from]++;
for(int i = 0;i < n;i++)g[i] = new Edge[p[i]];
for(Edge e : edges)g[e.from][--p[e.from]] = e;
return g;
}
// NOT VERIFIED
public static Edge[][] compileWU(int n, List<Edge> edges)
{
Edge[][] g = new Edge[n][];
// cloning
for(int i = edges.size()-1;i >= 0;i--){
Edge origin = edges.get(i);
Edge back = new Edge(origin.to, origin.from, origin.capacity, origin.cost);
edges.add(back);
}
for(int i = edges.size()-1;i >= 0;i--){
Edge origin = edges.get(i);
Edge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);
clone.flow = origin.capacity;
clone.complement = origin;
origin.complement = clone;
edges.add(clone);
}
int[] p = new int[n];
for(Edge e : edges)p[e.from]++;
for(int i = 0;i < n;i++)g[i] = new Edge[p[i]];
for(Edge e : edges)g[e.from][--p[e.from]] = e;
return g;
}
public static class DQ {
public int[] q;
public int n;
protected int pt, ph;
public DQ(int n){ this.n = Integer.highestOneBit(n)<<1; q = new int[this.n]; pt = ph = 0; }
public void addLast(int x){ q[ph] = x; ph = ph+1&n-1; }
public void addFirst(int x){ pt = pt+n-1&n-1; q[pt] = x; }
public int pollFirst(){ int ret = q[pt]; pt = pt+1&n-1; return ret; }
public int pollLast(){ ph = ph+n-1&n-1; int ret = q[ph]; return ret; }
public int getFirst(){ return q[pt]; }
public int getFirst(int k){ return q[pt+k&n-1]; }
public int getLast(){ return q[ph+n-1&n-1]; }
public int getLast(int k){ return q[ph+n-k-1&n-1]; }
public void clear(){ pt = ph = 0; }
public int size(){ return ph-pt+n&n-1; }
public boolean isEmpty(){ return ph==pt; }
}
public static long solveMinCostFlowWithSPFA(Edge[][] g, int source, int sink, long all)
{
int n = g.length;
long mincost = 0;
final int[] d = new int[n];
DQ q = new DQ(n);
boolean[] inq = new boolean[n];
while(all > 0){
// shortest path src->sink
Edge[] inedge = new Edge[n];
Arrays.fill(d, Integer.MAX_VALUE / 2);
d[source] = 0;
q.addLast(source);
while(!q.isEmpty()){
int cur = q.pollFirst();
inq[cur] = false;
for(Edge ne : g[cur]){
if(ne.capacity - ne.flow > 0){
int nd = d[cur] + ne.cost;
if(d[ne.to] > nd){
inedge[ne.to] = ne;
d[ne.to] = nd;
if(!inq[ne.to]){
q.addLast(ne.to);
inq[ne.to] = true;
}
}
}
}
}
if(inedge[sink] == null)break;
long minflow = all;
long sumcost = 0;
for(Edge e = inedge[sink];e != null;e = inedge[e.from]){
if(e.capacity - e.flow < minflow)minflow = e.capacity - e.flow;
sumcost += e.cost;
}
mincost += minflow * sumcost;
for(Edge e = inedge[sink];e != null;e = inedge[e.from]){
e.flow += minflow;
e.complement.flow -= minflow;
}
all -= minflow;
}
return mincost;
}
static int[][] packU(int n, int[] from, int[] to) {
int[][] g = new int[n][];
int[] p = new int[n];
for (int f : from)
p[f]++;
for (int t : to)
p[t]++;
for (int i = 0; i < n; i++)
g[i] = new int[p[i]];
for (int i = 0; i < from.length; i++) {
g[from[i]][--p[from[i]]] = to[i];
g[to[i]][--p[to[i]]] = from[i];
}
return g;
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new G().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, dd, bb;
int[] uu, vv, uv, cost;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
dd = new int[n_];
bb = new int[n_];
qq = new int[nq];
iq = new boolean[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
int[] qq;
int nq = 1 << 20, head, cnt;
boolean[] iq;
void enqueue(int v) {
if (iq[v])
return;
if (head + cnt == nq) {
if (cnt * 4 <= nq)
System.arraycopy(qq, head, qq, 0, cnt);
else {
int[] qq_ = new int[nq *= 2];
System.arraycopy(qq, head, qq_, 0, cnt);
qq = qq_;
}
head = 0;
}
qq[head + cnt++] = v; iq[v] = true;
}
int dequeue() {
int u = qq[head++]; cnt--; iq[u] = false;
return u;
}
boolean spfa(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
head = cnt = 0;
enqueue(s);
while (cnt > 0) {
int u = dequeue();
int d = dd[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && dd[v] > d) {
pi[v] = p;
dd[v] = d;
bb[v] = h_;
enqueue(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
while (spfa(s, t))
push1(s, t);
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
import java.io.*;
import java.util.*;
public class G{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.flush();out.close();
}
static class TaskE {
class MinCostMaxFlow{
ArrayList<Edge> al[];
Edge ja[][];
int d[]; // shortest distances
int N , S , T , maxFlow ; int minCost;
final int gmax = Integer.MAX_VALUE / 100;
int edges = 0;
class Edge{
int u , flow, rid, cost;
Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}
}
void addEdge(int u , int v , int flow , int cost){
int lu = al[u].size(), lv = al[v].size();
al[u].add(new Edge(v, flow, cost, lv));
al[v].add(new Edge(u, 0, -cost, lu));
}
void convertToArray(){
ja = new Edge[N][];
for(int i = 0; i < N; i++){
int sz = al[i].size();
ja[i] = new Edge[sz];
for(int j = 0; j < sz; j++){
ja[i][j] = al[i].get(j);
}
al[i].clear();
}
}
MinCostMaxFlow(int n , int source , int sink){
N = n; S = source; T = sink; maxFlow = 0; minCost = 0;
al = new ArrayList[N];
d = new int[N];
for(int i = 0; i < N; i++){
al[i] = new ArrayList<>();
}
}
boolean BellmanFord(boolean check){
d[0] = 0;
for(int i = 0; i < N - 1; i++){
for(int j = 0; j < N; j++){
for(Edge e : ja[j]){
if(e.flow == 0)continue; // not to consider reverse edges
d[e.u] = Math.min(d[e.u] , d[j] + e.cost);
}
}
}
if(check){// check for negative cycles
for(int j = 0; j < N; j++){
for(Edge e : ja[j]){
if(e.flow == 0)continue;
if(d[j] + e.cost < d[e.u]) return false;
}
}
}return true;
}
int node[]; // present node
int visit[]; // 0 -> not added 1 -> not removed 2 -> removed
int prv[], prve[]; // previous node for augmentation
int dist[]; // min dist
boolean simple(){
node = new int[N];
visit = new int[N];
prv = new int[N];
prve = new int[N];
dist = new int[N]; Arrays.fill(dist , gmax);
node[0] = S; dist[0] = 0;
int front = 1, back = 0;
while(front != back){
int u = node[back++]; int distu = dist[u];
if(back == N)back = 0;
visit[u] = 2;
for(int i = 0; i < ja[u].length; i++){
Edge e = ja[u][i];
if(e.flow == 0)continue;
int cdist = distu + e.cost; // no need of reduced cost
if(cdist < dist[e.u]){
if(visit[e.u] == 0){
node[front] = e.u;
if(++front == N)front = 0;
}else if(visit[e.u] == 2){
if(--back == -1)back += N;
node[back] = e.u;
}
visit[e.u] = 1;
prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;
}
}
}
return visit[T] != 0;
}
class pair{
int F; int S;
pair(int a, int b){F = a; S = b;}
}
boolean dijkstra(){
visit = new int[N];
prv = new int[N];
prve = new int[N];
dist = new int[N]; Arrays.fill(dist, gmax);
PriorityQueue<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));
pq.add(new pair(S , 0)); dist[0] = 0;
o : while(!pq.isEmpty()){
pair p = pq.poll();
while(dist[p.F] < p.S){
if(pq.isEmpty()) break o; // had a better val
p = pq.poll();
}
visit[p.F] = 2;
for(int i = 0; i < ja[p.F].length; i++){
Edge e = ja[p.F][i];
if(e.flow == 0)continue; // important
int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost
if(cdist < dist[e.u]){
if(visit[e.u] == 2) return false;
pq.add(new pair(e.u , cdist));
dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;
visit[e.u] = 1;
}
}
}
return visit[T] != 0;
}
int augment(){
int p = T; int min = gmax;
while(p != 0){
int pp = prv[p], pe = prve[p];
int val = ja[pp][pe].flow;
min = Math.min(min , val);
p = pp;
}
p = T;
while(p != 0){
int pp = prv[p], pe = prve[p];
ja[pp][pe].flow -= min;
ja[p][ja[pp][pe].rid].flow += min;
p = pp;
}
maxFlow += min;
return min;
}
// if(dist[T] >= 0)return true; // non contributing flow
boolean calSimple(){
// uncomment to check for negative cycles
/* boolean possible = BellmanFord(true);
if(!possible) return false; */
while(simple()){
/*if(dist[T] >= 0)return true;*/
minCost += dist[T] * augment();
}
return true;
}
void updPotential(){
for(int i = 0; i < N; i++){
if(visit[i] != 0){
d[i] += dist[i] - dist[S];
}
}
}
boolean calWithPotential(){
// set true to check for negative cycles
// boolean possible = BellmanFord(false);
// if(!possible) return false;
while(dijkstra()){
int min = dist[T] + d[T] - d[S]; // getting back the original cost
/*if(dist[T] >= 0)return true;*/
minCost += min * augment();
updPotential();
}
return true;
}
}
int n , m, k, c, d, a[], f[];
public void solve(int testNumber, InputReader in, PrintWriter out) {
n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();
// S + n
int maxl = n + k, T = n * maxl + 1;
MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);
a = new int[k + 1]; f = new int[n + 1];
for(int i = 1; i <= k; i++){
a[i] = in.nextInt();
f[a[i]]++;
}
for(int i = 1; i <= n; i++){
if(f[i] == 0)continue;
ans.addEdge(0 , i , f[i], 0);
}
for(int i = 2; i <= n; i++){
for(int l = 0; l < maxl - 1; l++){
ans.addEdge(l * n + i , (l + 1) * n + i, k, c);
}
}
for(int i = 1; i <= m; i++){
int a = in.nextInt(), b = in.nextInt();
for(int l = 0; l < maxl - 1; l++){
for(int p = 1; p <= k; p++){
if(a != 1)
ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);
if(b != 1)
ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);
}
}
}
for(int l = 1; l < maxl; l++){
ans.addEdge(l * n + 1, T, k, 0);
}
ans.convertToArray();
ans.calWithPotential();
// ans.calSimple();
if(ans.maxFlow != k){
out.println("BUG");
}else{
out.println((int)ans.minCost);
}
}
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
st = null;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out, true); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, kk;
int[] uu, vv, uv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
kk = new int[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
boolean dijkstra(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int k = kk[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && kk[v] > k) {
if (pi[v] != INF)
pq.remove(v);
pi[v] = p;
kk[v] = k;
pq.add(v);
}
}
}
return pi[t] != INF;
}
int dfs(int u, int t, int c) {
if (u == t || c == 0)
return c;
int k = kk[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj) {
int h = h_ >> 1;
int v = u ^ uv[h];
if (kk[v] != k)
continue;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]), f;
if (pi[v] == p && (f = dfs(v, t, Math.min(c, cc[h_]))) != 0) {
cc[h_] -= f; cc[h_ ^ 1] += f;
return f;
}
}
kk[u] = INF;
return 0;
}
int edmonds_karp(int s, int t) {
cost_ = Arrays.copyOf(cost, m_);
while (dijkstra(s, t)) {
while (dfs(s, t, INF) > 0)
;
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
import java.io.*;
import java.util.*;
public class G{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.flush();out.close();
}
static class TaskE {
class MinCostMaxFlow{
ArrayList<Edge> al[];
Edge ja[][];
int d[]; // shortest distances
int N , S , T , maxFlow ; int minCost;
final int gmax = Integer.MAX_VALUE / 100;
int edges = 0;
class Edge{
int u , flow, rid, cost;
Edge(int a, int b, int c, int d){u = a; flow = b; cost = c; rid = d;}
}
void addEdge(int u , int v , int flow , int cost){
int lu = al[u].size(), lv = al[v].size();
al[u].add(new Edge(v, flow, cost, lv));
al[v].add(new Edge(u, 0, -cost, lu));
}
void convertToArray(){
ja = new Edge[N][];
for(int i = 0; i < N; i++){
int sz = al[i].size();
ja[i] = new Edge[sz];
for(int j = 0; j < sz; j++){
ja[i][j] = al[i].get(j);
}
al[i].clear();
}
}
MinCostMaxFlow(int n , int source , int sink){
N = n; S = source; T = sink; maxFlow = 0; minCost = 0;
al = new ArrayList[N];
d = new int[N];
for(int i = 0; i < N; i++){
al[i] = new ArrayList<>();
}
}
boolean BellmanFord(boolean check){
d[0] = 0;
for(int i = 0; i < N - 1; i++){
for(int j = 0; j < N; j++){
for(Edge e : ja[j]){
if(e.flow == 0)continue; // not to consider reverse edges
d[e.u] = Math.min(d[e.u] , d[j] + e.cost);
}
}
}
if(check){// check for negative cycles
for(int j = 0; j < N; j++){
for(Edge e : ja[j]){
if(e.flow == 0)continue;
if(d[j] + e.cost < d[e.u]) return false;
}
}
}return true;
}
int node[]; // present node
int visit[]; // 0 -> not added 1 -> not removed 2 -> removed
int prv[], prve[]; // previous node for augmentation
int dist[]; // min dist
boolean simple(){
node = new int[N];
visit = new int[N];
prv = new int[N];
prve = new int[N];
dist = new int[N]; Arrays.fill(dist , gmax);
node[0] = S; dist[0] = 0;
int front = 1, back = 0;
while(front != back){
int u = node[back++]; int distu = dist[u];
if(back == N)back = 0;
visit[u] = 2;
for(int i = 0; i < ja[u].length; i++){
Edge e = ja[u][i];
if(e.flow == 0)continue;
int cdist = distu + e.cost; // no need of reduced cost
if(cdist < dist[e.u]){
if(visit[e.u] == 0){
node[front] = e.u;
if(++front == N)front = 0;
}else if(visit[e.u] == 2){
if(--back == -1)back += N;
node[back] = e.u;
}
visit[e.u] = 1;
prve[e.u] = i; prv[e.u] = u; dist[e.u] = cdist;
}
}
}
return visit[T] != 0;
}
class pair{
int F; int S;
pair(int a, int b){F = a; S = b;}
}
boolean dijkstra(){
visit = new int[N];
prv = new int[N];
prve = new int[N];
dist = new int[N]; Arrays.fill(dist, gmax);
PriorityQueue<pair> pq = new PriorityQueue<>((A, B) -> Double.compare(A.S , B.S));
pq.add(new pair(S , 0)); dist[0] = 0;
o : while(!pq.isEmpty()){
pair p = pq.poll();
while(dist[p.F] < p.S){
if(pq.isEmpty()) break o; // had a better val
p = pq.poll();
}
visit[p.F] = 2;
for(int i = 0; i < ja[p.F].length; i++){
Edge e = ja[p.F][i];
if(e.flow == 0)continue; // important
int cdist = p.S + (e.cost + d[p.F] - d[e.u]); // reduced cost
if(cdist < dist[e.u]){
if(visit[e.u] == 2) return false;
pq.add(new pair(e.u , cdist));
dist[e.u] = cdist; prv[e.u] = p.F; prve[e.u] = i;
visit[e.u] = 1;
}
}
}
return visit[T] != 0;
}
int augment(){
int p = T; int min = gmax;
while(p != 0){
int pp = prv[p], pe = prve[p];
int val = ja[pp][pe].flow;
min = Math.min(min , val);
p = pp;
}
p = T;
while(p != 0){
int pp = prv[p], pe = prve[p];
ja[pp][pe].flow -= min;
ja[p][ja[pp][pe].rid].flow += min;
p = pp;
}
maxFlow += min;
return min;
}
// if(dist[T] >= 0)return true; // non contributing flow
boolean calSimple(){
// uncomment to check for negative cycles
/* boolean possible = BellmanFord(true);
if(!possible) return false; */
while(simple()){
/*if(dist[T] >= 0)return true;*/
minCost += dist[T] * augment();
}
return true;
}
void updPotential(){
for(int i = 0; i < N; i++){
if(visit[i] != 0){
d[i] += dist[i] - dist[S];
}
}
}
boolean calWithPotential(){
// set true to check for negative cycles
// boolean possible = BellmanFord(false);
// if(!possible) return false;
while(dijkstra()){
int min = dist[T] + d[T] - d[S]; // getting back the original cost
/*if(dist[T] >= 0)return true;*/
minCost += min * augment();
updPotential();
}
return true;
}
}
int n , m, k, c, d, a[], f[];
public void solve(int testNumber, InputReader in, PrintWriter out) {
n = in.nextInt(); m = in.nextInt(); k = in.nextInt(); c = in.nextInt(); d= in.nextInt();
// S + n
int maxl = n + k, T = n * maxl + 1;
MinCostMaxFlow ans = new MinCostMaxFlow(T + 1, 0, T);
a = new int[k + 1]; f = new int[n + 1];
for(int i = 1; i <= k; i++){
a[i] = in.nextInt();
f[a[i]]++;
}
for(int i = 1; i <= n; i++){
if(f[i] == 0)continue;
ans.addEdge(0 , i , f[i], 0);
}
for(int i = 2; i <= n; i++){
for(int l = 0; l < maxl - 1; l++){
ans.addEdge(l * n + i , (l + 1) * n + i, k, c);
}
}
for(int i = 1; i <= m; i++){
int a = in.nextInt(), b = in.nextInt();
for(int l = 0; l < maxl - 1; l++){
for(int p = 1; p <= k; p++){
if(a != 1)
ans.addEdge(n * l + a, n * (l + 1) + b, 1, d * (2 * p - 1) + c);
if(b != 1)
ans.addEdge(n * l + b, n * (l + 1) + a, 1, d * (2 * p - 1) + c);
}
}
}
for(int l = 1; l < maxl; l++){
ans.addEdge(l * n + 1, T, k, 0);
}
ans.convertToArray();
// ans.calWithPotential();
ans.calSimple();
if(ans.maxFlow != k){
out.println("BUG");
}else{
out.println((int)ans.minCost);
}
}
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
st = null;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, bb;
int[] uu, vv, uv, cost;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
bb = new int[n_];
qq = new int[nq];
iq = new boolean[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
int[] qq;
int nq = 1 << 20, head, cnt;
boolean[] iq;
void enqueue(int v) {
if (iq[v])
return;
if (head + cnt == nq) {
if (cnt * 2 <= nq)
System.arraycopy(qq, head, qq, 0, cnt);
else {
int[] qq_ = new int[nq *= 2];
System.arraycopy(qq, head, qq_, 0, cnt);
qq = qq_;
}
head = 0;
}
qq[head + cnt++] = v; iq[v] = true;
}
int dequeue() {
int u = qq[head++]; cnt--; iq[u] = false;
return u;
}
boolean spfa(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
head = cnt = 0;
enqueue(s);
while (cnt > 0) {
int u = dequeue();
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
int v = u ^ uv[h];
if (pi[v] > p) {
pi[v] = p;
bb[v] = h_;
enqueue(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
while (spfa(s, t))
push1(s, t);
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, kk, bb;
int[] uu, vv, uv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
kk = new int[n_];
bb = new int[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cost_ = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
boolean dijkstra(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int k = kk[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && kk[v] > k) {
if (pi[v] != INF)
pq.remove(v);
pi[v] = p;
kk[v] = k;
bb[v] = h_;
pq.add(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
System.arraycopy(cost, 0, cost_, 0, m_);
while (dijkstra(s, t)) {
push1(s, t);
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
public class G {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), m = ni(), K = ni(), C = ni(), D = ni();
int[] a = na(K);
int[] from = new int[m];
int[] to = new int[m];
for (int i = 0; i < m; i++) {
from[i] = ni() - 1;
to[i] = ni() - 1;
}
int[][] g = packU(n, from, to);
List<Edge> es = new ArrayList<>();
int time = 100;
for(int i = 0;i < n;i++){
for(int j = 0;j < time-1;j++){
es.add(new Edge(i*time+j, i*time+j+1, 99, C));
}
}
for(int i = 0;i < n;i++){
for(int e : g[i]){
for(int j = 0;j < time-1;j++){
for(int k = 0;k < n;k++){
es.add(new Edge(i*time+j, e*time+j+1, 1, C+D*(2*k+1)));
}
}
}
}
int src = time*n, sink = src+1;
for(int i = 0;i < K;i++){
es.add(new Edge(src, (a[i]-1)*time+0, 1, 0));
}
for(int i = 0;i < time;i++){
es.add(new Edge(0*time+i, sink, 99, 0));
}
out.println(solveMinCostFlowWithSPFA(compileWD(sink+1, es), src, sink, 99));
}
public static class Edge
{
public int from, to;
public int capacity;
public int cost;
public int flow;
public Edge complement;
// public int iniflow;
public Edge(int from, int to, int capacity, int cost) {
this.from = from;
this.to = to;
this.capacity = capacity;
this.cost = cost;
}
}
public static Edge[][] compileWD(int n, List<Edge> edges)
{
Edge[][] g = new Edge[n][];
// cloning
for(int i = edges.size()-1;i >= 0;i--){
Edge origin = edges.get(i);
Edge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);
clone.flow = origin.capacity;
clone.complement = origin;
origin.complement = clone;
edges.add(clone);
}
int[] p = new int[n];
for(Edge e : edges)p[e.from]++;
for(int i = 0;i < n;i++)g[i] = new Edge[p[i]];
for(Edge e : edges)g[e.from][--p[e.from]] = e;
return g;
}
// NOT VERIFIED
public static Edge[][] compileWU(int n, List<Edge> edges)
{
Edge[][] g = new Edge[n][];
// cloning
for(int i = edges.size()-1;i >= 0;i--){
Edge origin = edges.get(i);
Edge back = new Edge(origin.to, origin.from, origin.capacity, origin.cost);
edges.add(back);
}
for(int i = edges.size()-1;i >= 0;i--){
Edge origin = edges.get(i);
Edge clone = new Edge(origin.to, origin.from, origin.capacity, -origin.cost);
clone.flow = origin.capacity;
clone.complement = origin;
origin.complement = clone;
edges.add(clone);
}
int[] p = new int[n];
for(Edge e : edges)p[e.from]++;
for(int i = 0;i < n;i++)g[i] = new Edge[p[i]];
for(Edge e : edges)g[e.from][--p[e.from]] = e;
return g;
}
public static class DQ {
public int[] q;
public int n;
protected int pt, ph;
public DQ(int n){ this.n = Integer.highestOneBit(n)<<1; q = new int[this.n]; pt = ph = 0; }
public void addLast(int x){ q[ph] = x; ph = ph+1&n-1; }
public void addFirst(int x){ pt = pt+n-1&n-1; q[pt] = x; }
public int pollFirst(){ int ret = q[pt]; pt = pt+1&n-1; return ret; }
public int pollLast(){ ph = ph+n-1&n-1; int ret = q[ph]; return ret; }
public int getFirst(){ return q[pt]; }
public int getFirst(int k){ return q[pt+k&n-1]; }
public int getLast(){ return q[ph+n-1&n-1]; }
public int getLast(int k){ return q[ph+n-k-1&n-1]; }
public void clear(){ pt = ph = 0; }
public int size(){ return ph-pt+n&n-1; }
public boolean isEmpty(){ return ph==pt; }
}
public static long solveMinCostFlowWithSPFA(Edge[][] g, int source, int sink, long all)
{
int n = g.length;
long mincost = 0;
final int[] d = new int[n];
DQ q = new DQ(n);
boolean[] inq = new boolean[n];
while(all > 0){
// shortest path src->sink
Edge[] inedge = new Edge[n];
Arrays.fill(d, Integer.MAX_VALUE / 2);
d[source] = 0;
q.addLast(source);
while(!q.isEmpty()){
int cur = q.pollFirst();
inq[cur] = false;
for(Edge ne : g[cur]){
if(ne.capacity - ne.flow > 0){
int nd = d[cur] + ne.cost;
if(d[ne.to] > nd){
inedge[ne.to] = ne;
d[ne.to] = nd;
if(!inq[ne.to]){
q.addLast(ne.to);
inq[ne.to] = true;
}
}
}
}
}
if(inedge[sink] == null)break;
long minflow = all;
long sumcost = 0;
for(Edge e = inedge[sink];e != null;e = inedge[e.from]){
if(e.capacity - e.flow < minflow)minflow = e.capacity - e.flow;
sumcost += e.cost;
}
mincost += minflow * sumcost;
for(Edge e = inedge[sink];e != null;e = inedge[e.from]){
e.flow += minflow;
e.complement.flow -= minflow;
}
all -= minflow;
}
return mincost;
}
static int[][] packU(int n, int[] from, int[] to) {
int[][] g = new int[n][];
int[] p = new int[n];
for (int f : from)
p[f]++;
for (int t : to)
p[t]++;
for (int i = 0; i < n; i++)
g[i] = new int[p[i]];
for (int i = 0; i < from.length; i++) {
g[from[i]][--p[from[i]]] = to[i];
g[to[i]][--p[to[i]]] = from[i];
}
return g;
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new G().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
} | cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, dd, bb;
int[] uu, vv, uv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
dd = new int[n_];
bb = new int[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cost_ = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
boolean dijkstra(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int d = dd[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && dd[v] > d) {
if (pi[v] != INF)
pq.remove(v);
pi[v] = p;
dd[v] = d;
bb[v] = h_;
pq.add(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
cost_ = Arrays.copyOf(cost, m_);
while (dijkstra(s, t)) {
push1(s, t);
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, dd, bb;
int[] uu, vv, uv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
dd = new int[n_];
bb = new int[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
boolean dijkstra(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int d = dd[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && dd[v] > d) {
if (pi[v] != INF)
pq.remove(v);
pi[v] = p;
dd[v] = d;
bb[v] = h_;
pq.add(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
cost_ = Arrays.copyOf(cost, m_);
while (dijkstra(s, t)) {
push1(s, t);
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, dd, bb;
int[] uu, vv, uv, cost;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
dd = new int[n_];
bb = new int[n_];
qq = new int[nq];
iq = new boolean[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
int[] qq;
int nq = 1 << 20, head, cnt;
boolean[] iq;
void enqueue(int v) {
if (iq[v])
return;
if (head + cnt == nq) {
if (cnt * 2 <= nq)
System.arraycopy(qq, head, qq, 0, cnt);
else {
int[] qq_ = new int[nq *= 2];
System.arraycopy(qq, head, qq_, 0, cnt);
qq = qq_;
}
head = 0;
}
qq[head + cnt++] = v; iq[v] = true;
}
int dequeue() {
int u = qq[head++]; cnt--; iq[u] = false;
return u;
}
boolean spfa(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
head = cnt = 0;
enqueue(s);
while (cnt > 0) {
int u = dequeue();
int d = dd[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && dd[v] > d) {
pi[v] = p;
dd[v] = d;
bb[v] = h_;
enqueue(v);
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
while (spfa(s, t))
push1(s, t);
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, dd, bb;
int[] uu, vv, uv, cost;
boolean[] iq;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
dd = new int[n_];
bb = new int[n_];
iq = new boolean[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
boolean dijkstra(int s, int t) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : dd[u] != dd[v] ? dd[u] - dd[v] : u - v);
pq.add(s); iq[s] = true;
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
iq[u] = false;
int d = dd[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost[h] : -cost[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && dd[v] > d) {
if (iq[v]) {
pq.remove(v); iq[v] = false;
}
pi[v] = p;
dd[v] = d;
bb[v] = h_;
pq.add(v); iq[v] = true;
}
}
}
return pi[t] != INF;
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
while (dijkstra(s, t))
push1(s, t);
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, kk, bb;
int[] uu, vv, uv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
kk = new int[n_];
bb = new int[n_];
uu = new int[m_];
vv = new int[m_];
uv = new int[m_];
cost = new int[m_];
cost_ = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
uv[h] = u ^ v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
void dijkstra(int s) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int k = kk[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uv[h];
if (pi[v] > p || pi[v] == p && kk[v] > k) {
if (pi[v] < INF)
pq.remove(v);
pi[v] = p;
kk[v] = k;
bb[v] = h_;
pq.add(v);
}
}
}
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
void push1(int s, int t) {
for (int u = t, h_, h; u != s; u ^= uv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_]--; cc[h_ ^ 1]++;
}
}
int edmonds_karp(int s, int t) {
System.arraycopy(cost, 0, cost_, 0, m_);
while (true) {
dijkstra(s);
if (pi[t] == INF)
break;
push1(s, t);
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
import java.util.*;
import java.io.*;
public class GG {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int N = scanner.nextInt();
int M = scanner.nextInt();
int K = scanner.nextInt();
int C = scanner.nextInt();
int D = scanner.nextInt();
MinCostMaxFlowSolver solver = new EdmondsKarp();
int[] people = new int[K];
for(int i = 0; i < K; i++) people[i] = scanner.nextInt()-1;
Node src = solver.addNode();
Node snk = solver.addNode();
int amt = 150;
Node[][] timeNodes = new Node[N][amt];
for(int i = 0; i < N; i++) {
for(int j = 1; j < amt; j++) {
timeNodes[i][j] = solver.addNode();
if (j > 1) solver.link(timeNodes[i][j-1], timeNodes[i][j], Integer.MAX_VALUE, 0);
}
}
for(int i = 0; i < K; i++) {
solver.link(src, timeNodes[people[i]][1], 1, 0);
}
for(int i = 1; i < amt; i++) {
for(int j = 0; j < K; j++) {
solver.link(timeNodes[0][i], snk, 1, C*i-C);
}
}
for(int i =0; i < M; i++) {
int a = scanner.nextInt()-1;
int b = scanner.nextInt()-1;
for(int j = 1; j < amt-1; j++) {
int prev = 0;
for(int k = 1; k <= K; k++) {
solver.link(timeNodes[a][j], timeNodes[b][j + 1], 1, D*k*k- prev);
solver.link(timeNodes[b][j], timeNodes[a][j + 1], 1, D*k*k - prev);
prev = D * k * k;
}
}
}
long[] ret = solver.getMinCostMaxFlow(src, snk);
out.println(ret[1]);
out.flush();
}
public static class Node {
// thou shall not create nodes except through addNode()
private Node() { }
List<Edge> edges = new ArrayList<Edge>();
int index; // index in nodes array
}
public static class Edge
{
boolean forward; // true: edge is in original graph
Node from, to; // nodes connected
long flow; // current flow
final long capacity;
Edge dual; // reference to this edge's dual
long cost; // only used for MinCost.
protected Edge(Node s, Node d, long c, boolean f)
{
forward = f;
from = s;
to = d;
capacity = c;
}
long remaining() { return capacity - flow; }
void addFlow(long amount) {
flow += amount;
dual.flow -= amount;
}
}
public static abstract class MaxFlowSolver {
List<Node> nodes = new ArrayList<Node>();
public void link(Node n1, Node n2, long capacity) {
link(n1, n2, capacity, 1);
}
public void link(Node n1, Node n2, long capacity, long cost) {
Edge e12 = new Edge(n1, n2, capacity, true);
Edge e21 = new Edge(n2, n1, 0, false);
e12.dual = e21;
e21.dual = e12;
n1.edges.add(e12);
n2.edges.add(e21);
e12.cost = cost;
e21.cost = -cost;
}
void link(int n1, int n2, long capacity) {
link(nodes.get(n1), nodes.get(n2), capacity);
}
protected MaxFlowSolver(int n) {
for (int i = 0; i < n; i++)
addNode();
}
protected MaxFlowSolver() {
this(0);
}
public abstract long getMaxFlow(Node src, Node snk);
public Node addNode() {
Node n = new Node();
n.index = nodes.size();
nodes.add(n);
return n;
}
}
static abstract class MinCostMaxFlowSolver extends MaxFlowSolver {
// returns [maxflow, mincost]
abstract long [] getMinCostMaxFlow(Node src, Node snk);
// unavoidable boiler plate
MinCostMaxFlowSolver () { this(0); }
MinCostMaxFlowSolver (int n) { super(n); }
}
static class EdmondsKarp extends MinCostMaxFlowSolver
{
EdmondsKarp () { this(0); }
EdmondsKarp (int n) { super(n); }
long minCost;
@Override
public long [] getMinCostMaxFlow(Node src, Node snk) {
long maxflow = getMaxFlow(src, snk);
return new long [] { maxflow, minCost };
}
static final long INF = Long.MAX_VALUE/4;
@Override
public long getMaxFlow(Node src, Node snk) {
final int n = nodes.size();
final int source = src.index;
final int sink = snk.index;
long flow = 0;
long cost = 0;
long[] potential = new long[n]; // allows Dijkstra to work with negative edge weights
while (true) {
Edge[] parent = new Edge[n]; // used to store an augmenting path
long[] dist = new long[n]; // minimal cost to vertex
Arrays.fill(dist, INF);
dist[source] = 0;
PriorityQueue<Item> que = new PriorityQueue<Item>();
que.add(new Item(0, source));
while (!que.isEmpty()) {
Item item = que.poll();
if (item.dist != dist[item.v])
continue;
for (Edge e : nodes.get(item.v).edges) {
long temp = dist[item.v] + e.cost + potential[item.v] - potential[e.to.index];
if (e.capacity > e.flow && dist[e.to.index] > temp) {
dist[e.to.index] = temp;
parent[e.to.index] = e;
que.add(new Item(temp, e.to.index));
}
}
}
if (parent[sink] == null)
break;
for (int i = 0; i < n; i++)
if (parent[i] != null)
potential[i] += dist[i];
long augFlow = Long.MAX_VALUE;
for (int i = sink; i != source; i = parent[i].from.index)
augFlow = Math.min(augFlow, parent[i].capacity - parent[i].flow);
for (int i = sink; i != source; i = parent[i].from.index) {
Edge e = parent[i];
e.addFlow(augFlow);
cost += augFlow * e.cost;
}
flow += augFlow;
}
minCost = cost;
return flow;
}
static class Item implements Comparable<Item> {
long dist;
int v;
public Item(long dist, int v) {
this.dist = dist;
this.v = v;
}
public int compareTo(Item that) {
return Long.compare(this.dist, that.dist);
}
}
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner() {
this(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String readNextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readIntArray(int n) {
int[] a = new int[n];
for (int idx = 0; idx < n; idx++) {
a[idx] = nextInt();
}
return a;
}
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
// upsolve with rainboy
import java.io.*;
import java.util.*;
public class CF1187G extends PrintWriter {
CF1187G() { super(System.out); }
static class Scanner {
Scanner(InputStream in) { this.in = in; } InputStream in;
int k, l; byte[] bb = new byte[1 << 15];
byte getc() {
if (k >= l) {
k = 0;
try { l = in.read(bb); } catch (IOException e) { l = 0; }
if (l <= 0) return -1;
}
return bb[k++];
}
int nextInt() {
byte c = 0; while (c <= 32) c = getc();
int a = 0;
while (c > 32) { a = a * 10 + c - '0'; c = getc(); }
return a;
}
}
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1187G o = new CF1187G(); o.main(); o.flush();
}
static final int INF = 0x3f3f3f3f;
ArrayList[] aa_;
int n_, m_;
int[] pi, kk, bb;
int[] uu, vv, cost, cost_;
int[] cc;
void init() {
aa_ = new ArrayList[n_];
for (int u = 0; u < n_; u++)
aa_[u] = new ArrayList<Integer>();
pi = new int[n_];
kk = new int[n_];
bb = new int[n_];
uu = new int[m_];
vv = new int[m_];
cost = new int[m_];
cost_ = new int[m_];
cc = new int[m_ * 2];
m_ = 0;
}
void link(int u, int v, int cap, int cos) {
int h = m_++;
uu[h] = u;
vv[h] = v;
cost[h] = cos;
cc[h << 1 ^ 0] = cap;
aa_[u].add(h << 1 ^ 0);
aa_[v].add(h << 1 ^ 1);
}
void dijkstra(int s) {
Arrays.fill(pi, INF);
pi[s] = 0;
TreeSet<Integer> pq = new TreeSet<>((u, v) -> pi[u] != pi[v] ? pi[u] - pi[v] : kk[u] != kk[v] ? kk[u] - kk[v] : u - v);
pq.add(s);
Integer first;
while ((first = pq.pollFirst()) != null) {
int u = first;
int k = kk[u] + 1;
ArrayList<Integer> adj = aa_[u];
for (int h_ : adj)
if (cc[h_] > 0) {
int h = h_ >> 1;
int p = pi[u] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
int v = u ^ uu[h] ^ vv[h];
if (pi[v] > p || pi[v] == p && kk[v] > k) {
if (pi[v] < INF)
pq.remove(v);
pi[v] = p;
kk[v] = k;
bb[v] = h_;
pq.add(v);
}
}
}
}
void push(int s, int t) {
int c = INF;
for (int u = t, h_, h; u != s; u ^= uu[h] ^ vv[h]) {
h = (h_ = bb[u]) >> 1;
c = Math.min(c, cc[h_]);
}
for (int u = t, h_, h; u != s; u ^= uu[h] ^ vv[h]) {
h = (h_ = bb[u]) >> 1;
cc[h_] -= c; cc[h_ ^ 1] += c;
}
}
int edmonds_karp(int s, int t) {
System.arraycopy(cost, 0, cost_, 0, m_);
while (true) {
dijkstra(s);
if (pi[t] == INF)
break;
push(s, t);
for (int h = 0; h < m_; h++) {
int u = uu[h], v = vv[h];
if (pi[u] != INF && pi[v] != INF)
cost_[h] += pi[u] - pi[v];
}
}
int c = 0;
for (int h = 0; h < m_; h++)
c += cost[h] * cc[h << 1 ^ 1];
return c;
}
void main() {
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int[] ii = new int[k];
for (int h = 0; h < k; h++)
ii[h] = sc.nextInt() - 1;
ArrayList[] aa = new ArrayList[n];
for (int i = 0; i < n; i++)
aa[i] = new ArrayList<Integer>();
for (int h = 0; h < m; h++) {
int i = sc.nextInt() - 1;
int j = sc.nextInt() - 1;
aa[i].add(j);
aa[j].add(i);
}
int t = n + k + 1;
n_ = n * t + 1;
m_ = k + (m * 2 * k + n) * (t - 1);
init();
for (int i = 0; i < n; i++) {
ArrayList<Integer> adj = aa[i];
for (int s = 0; s < t - 1; s++) {
int u = i * t + s;
for (int j : adj) {
int v = j * t + s + 1;
for (int x = 1; x <= k; x++)
link(u, v, 1, c + (x * 2 - 1) * d);
}
}
}
for (int i = 0; i < n; i++)
for (int s = 0; s < t - 1; s++) {
int u = i * t + s, v = u + 1;
link(u, v, k, i == 0 ? 0 : c);
}
for (int h = 0; h < k; h++)
link(n_ - 1, ii[h] * t + 0, 1, 0);
println(edmonds_karp(n_ - 1, 0 * t + t - 1));
}
}
| cubic | 1187_G. Gang Up | CODEFORCES |
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] Args) throws Exception {
Scanner sc = new Scanner(new FileReader("input.txt"));
int n,m,k;
Integer lx,ly;
boolean d[][];
n = sc.nextInt(); m = sc.nextInt(); k = sc.nextInt();
d = new boolean [n+1][m+1];
for(int i=0;i<=n;++i)
for(int j=0;j<=m;++j)
d[i][j]=false;
Queue< pair > q = new LinkedList< pair >();
lx = ly = -1;
for(int i=0;i<k;++i){
int x,y; x = sc.nextInt(); y = sc.nextInt();
q.add(new pair(x,y)); lx = x; ly = y;
d[x][y]=true;
}
int dx [] = {0,0,1,-1};
int dy [] = {-1,1,0,0};
while(!q.isEmpty()){
pair tp = q.remove();
int x = tp.x; int y = tp.y;
for(int i=0;i<4;++i){
int nx = x+dx[i]; int ny = y+dy[i];
if(nx<1 || nx>n || ny<1 || ny>m || d[nx][ny] ) continue;
d[nx][ny]=true;
q.add(new pair(nx,ny));
lx = nx; ly = ny;
}
}
FileWriter fw = new FileWriter("output.txt");
fw.write(lx.toString()); fw.write(" "); fw.write(ly.toString());;
fw.flush();
}
}
class pair {
public int x,y;
public pair(int _x,int _y){ x = _x; y = _y; }
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.LinkedList;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.ArrayList;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Collection;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Queue;
import java.io.IOException;
import java.io.FileOutputStream;
import java.util.StringTokenizer;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author nasko
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream;
try {
inputStream = new FileInputStream("input.txt");
} catch (IOException e) {
throw new RuntimeException(e);
}
OutputStream outputStream;
try {
outputStream = new FileOutputStream("output.txt");
} catch (IOException e) {
throw new RuntimeException(e);
}
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int N = in.nextInt();
int M = in.nextInt();
int K = in.nextInt();
int[][] dist = new int[N+1][M+1];
for(int[] ini : dist) Arrays.fill(ini,1 << 30);
int best = 0;
ArrayList<Integer> result = new ArrayList<Integer>();
Queue<Integer> q = new LinkedList<Integer>();
for(int k = 0; k < K; ++k) {
int x = in.nextInt();
int y = in.nextInt();
dist[x][y] = 0;
q.offer(x);
q.offer(y);
}
int[] dx = new int[] { 1,-1,0,0 };
int[] dy = new int[] {0,0,1,-1};
while(!q.isEmpty()) {
int a = q.poll();
int b = q.poll();
for(int r = 0; r < 4; ++r) {
int x = a + dx[r];
int y = b + dy[r];
if(x >= 1 && x <= N && y >=1 && y <= M && dist[x][y] > dist[a][b] + 1) {
dist[x][y] = dist[a][b] + 1;
q.offer(x);
q.offer(y);
}
}
}
for(int i = 1; i <= N; ++i)
for(int j = 1; j <= M; ++j) best = Math.max(best,dist[i][j]);
for(int a = 1; a <= N; ++a)
for(int b = 1; b <= M; ++b) if(dist[a][b] == best) {
result.add(a);
result.add(b);
}
if(result.size() > 0) {
out.print(result.get(0) + " " + result.get(1));
}
out.println();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
public class SolutionC{
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(new File("input.txt"));
PrintWriter output = new PrintWriter("output.txt");
int N = sc.nextInt();
int M = sc.nextInt();
int K = sc.nextInt();
int[] x = new int[K];
int[] y = new int[K];
for(int i = 0 ; i < K ; i++){
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
int max = -1, max_x = -1, max_y = -1;
for(int i = 1 ; i <= N ; i++){
for(int j = 1 ; j <= M ; j++){
int min = Integer.MAX_VALUE;
for(int k = 0 ; k < K ; k++){
min = Math.min(min, Math.abs(x[k] - i) + Math.abs(y[k] - j));
}
if(min > max){
max = min;
max_x = i;
max_y = j;
}
}
}
output.println(max_x + " " + max_y);
output.flush();
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
import java.awt.*;
public class PracticeProblem
{
/*
* This FastReader code is taken from GeeksForGeeks.com
* https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
*
* The article was written by Rishabh Mahrsee
*/
public static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader() throws FileNotFoundException
{
br = new BufferedReader(new FileReader(new File("input.txt")));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static FastReader in;
public static PrintWriter out;
public static final int INF = Integer.MAX_VALUE;
public static int n, m;
public static final int[] dr = {-1, 0, 0, +1};
public static final int[] dc = {0, -1, +1, 0};
public static void main(String[] args) throws FileNotFoundException
{
in = new FastReader();
out = new PrintWriter(new File("output.txt"));
solve();
out.close();
}
private static void solve()
{
n = in.nextInt();
m = in.nextInt();
int k = in.nextInt();
int[][] timeToBurn = new int[n][m];
for (int i = 0; i < n; i++)
Arrays.fill(timeToBurn[i], INF);
for (int i = 0; i < k; i++)
{
int r = in.nextInt() - 1;
int c = in.nextInt() - 1;
for (int j = 0; j < n; j++)
{
for (int l = 0; l < m; l++)
{
timeToBurn[j][l] = min(timeToBurn[j][l], abs(r - j) + abs(c - l));
}
}
}
int max = -1;
Point p = null;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (timeToBurn[i][j] > max)
{
max = timeToBurn[i][j];
p = new Point(i, j);
}
}
}
out.println((p.x + 1) + " " + (p.y + 1));
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
public class Main implements Runnable {
public void solve() throws IOException {
int N = nextInt();
int M = nextInt();
int B = nextInt();
int[][] burn = new int[B][2];
for(int i = 0; i < B; i++){
burn[i][0] = nextInt();
burn[i][1] = nextInt();
}
int ansx = -1;
int ansy = -1;
int ans = -1;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
int burnAt = Integer.MAX_VALUE;
for(int k = 0; k < B; k++){
int now = distance(i, j, burn[k][0], burn[k][1]);
burnAt = Math.min(burnAt, now);
}
//System.out.println(burnAt + " " + i + " " + j);
if(burnAt >= ans){
ans = burnAt;
ansx = i;
ansy = j;
}
}
}
out.println(ansx + " " + ansy);
}
private int distance(int x, int y, int xx, int yy){
//withour sqrt
return Math.abs(xx - x) + Math.abs(yy - y);
}
//-----------------------------------------------------------
public static void main(String[] args) {
new Main().run();
}
public void run() {
try {
//in = new BufferedReader(new InputStreamReader(System.in));
in = new BufferedReader(new FileReader(new File("input.txt")));
out = new PrintWriter(new FileWriter(new File("output.txt")));
tok = null;
solve();
in.close();
out.close();
} catch (IOException e) {
System.exit(0);
}
}
public String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
PrintWriter out;
BufferedReader in;
StringTokenizer tok;
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
public class FireAgain {
public static void main(String[] args) throws IOException {
BufferedReader readData = new BufferedReader(new FileReader("input.txt"));
PrintWriter writer = new PrintWriter(new File("output.txt"));
String line = readData.readLine();
String[] temp = line.split(" ");
int n = Integer.valueOf(temp[0]);
int m = Integer.valueOf(temp[1]);
int x = 0, y = 0;
line = readData.readLine();
int k = Integer.valueOf(line);
boolean[][] visited = new boolean[n + 1][m + 1];
Queue<Integer> qX = new LinkedList<Integer>();
Queue<Integer> qY = new LinkedList<Integer>();
line = readData.readLine();
String[] temp2 = line.split(" ");
for (int i = 0; i < temp2.length - 1; i+=2) {
x = Integer.valueOf(temp2[i]);
y = Integer.valueOf(temp2[i + 1]);
visited[x][y] = true;
qX.add(x);
qY.add(y);
}
while (!qX.isEmpty()) {
x = qX.poll();
y = qY.poll();
if (x >= 2 && !visited[x - 1][y]) {
visited[x - 1][y] = true;
qX.add(x - 1);
qY.add(y);
}
if (x + 1 <= n && !visited[x + 1][y]) {
visited[x + 1][y] = true;
qX.add(x + 1);
qY.add(y);
}
if (y >= 2 && !visited[x][y - 1]) {
visited[x][y - 1] = true;
qX.add(x);
qY.add(y - 1);
}
if (y + 1 <= m && !visited[x][y + 1]) {
visited[x][y + 1] = true;
qX.add(x);
qY.add(y + 1);
}
}
writer.write(x + " ");
writer.write(y + " ");
writer.close();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new FileReader(new File("input.txt")));
PrintWriter pw = new PrintWriter(new File("output.txt"));
StringTokenizer st;
st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken()),
m = Integer.parseInt(st.nextToken()),
k = Integer.parseInt(in.readLine());
int[][] A = new int[n][m];
st = new StringTokenizer(in.readLine());
for (int i = 0 ; i < k ; i++) {
int x1 = Integer.parseInt(st.nextToken()) - 1,
y1 = Integer.parseInt(st.nextToken()) - 1;
A[x1][y1] = -10000000;
for (int j = 0 ; j < n ; j++) {
for (int g = 0 ; g < m ; g++) {
if (A[j][g] == 0 || (A[j][g] > (Math.abs(y1 - g) + Math.abs(x1 - j)))) {
A[j][g] = (Math.abs(y1 - g) + Math.abs(x1 - j));
}
}
}
}
int f = 0, h = 0;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) {
if (A[i][j] != -10000000) {
f = i;
h = j;
}
}
}
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) {
if (A[i][j] > A[f][h] && A[i][j] != -10000000) {
f = i;
h = j;
}
}
}
// for (int i = 0 ; i < n ; i++) for (int j = 0 ; j < m ; j++) System.out.println(A[i][j]);
pw.println((f + 1) + " " + (h + 1));
pw.close();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class C35C_BFS_Fire {
public static boolean[][] burning;
public static LinkedList<int[]> LitTrees; //which is best to use
public static int N, M;
public static int[] lastTree;
public static void main(String[] args) throws IOException {
// InputStreamReader stream = new InputStreamReader(System.in);
// BufferedReader input = new BufferedReader(stream);
BufferedReader input = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
StringTokenizer dataR = new StringTokenizer(input.readLine());
N = Integer.parseInt(dataR.nextToken());
M = Integer.parseInt(dataR.nextToken());
burning = new boolean[N+1][M+1];
StringTokenizer dataR1 = new StringTokenizer(input.readLine());
int K = Integer.parseInt(dataR1.nextToken());
StringTokenizer dataR2 = new StringTokenizer(input.readLine());
LitTrees = new LinkedList<int[]>();
for (int j = 0; j < K; j++){
int x = Integer.parseInt(dataR2.nextToken());
int y = Integer.parseInt(dataR2.nextToken());
int[] coord = {x, y};
LitTrees.add(coord);
burning[x][y] = true;
}
spread();
out.println(lastTree[0] + " " + lastTree[1]);
out.close();
}
public static void spread(){
while(!LitTrees.isEmpty()){
int[] studying = LitTrees.remove(); //is iterator faster
LinkedList<int[]> ll = new LinkedList<int[]>();
if(studying[0]-1 >= 1) ll.add(new int[]{studying[0]-1, studying[1]});
if(studying[1]-1 >= 1) ll.add(new int[]{studying[0], studying[1]-1});
if(studying[1]+1 < M+1) ll.add(new int[]{studying[0], studying[1]+1});
if(studying[0]+1 < N+1) ll.add(new int[]{studying[0]+1, studying[1]});
while(!ll.isEmpty()) {
int[] focus = ll.remove();
if(!burning[focus[0]][focus[1]]) {
LitTrees.add(focus);
burning[focus[0]][focus[1]] = true;
}
}
lastTree = studying;
}
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
static int n, m, k;
static int inf = (int) 1e9;
static class Pair {
int x, y;
Pair(int a, int b) {
x = a; y = b;
}
}
static int[] dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
static boolean valid(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
static int[][] bfs(int[] xs, int[] ys) {
int[][] dist = new int[n][m];
for(int i = 0; i < n; i++)
Arrays.fill(dist[i], inf);
Queue<Pair> q = new LinkedList<>();
for(int i = 0; i < k; i++) {
dist[xs[i]][ys[i]] = 0;
q.add(new Pair(xs[i], ys[i]));
}
while(!q.isEmpty()) {
Pair p = q.remove();
for(int d = 0; d < 4; d++) {
int nx = p.x + dx[d], ny = p.y + dy[d];
if(valid(nx, ny) && dist[nx][ny] == inf) {
dist[nx][ny] = dist[p.x][p.y] + 1;
q.add(new Pair(nx, ny));
}
}
}
return dist;
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner();
int n = in.nextInt() ;
int m = in.nextInt();
int k = in.nextInt();
int x[] = new int[k] ;
int y[] = new int[k] ;
int trees [][] = new int [n][m] ;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
trees[i][j]=Integer.MAX_VALUE ;
for (int i = 0; i < k; i++)
{
x[i]=in.nextInt()-1;
y[i]=in.nextInt()-1;
trees[x[i]][y[i]]=0 ;
}
int dis = Integer.MIN_VALUE ; ;
int xp=0; ;
int yp=0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if(trees[i][j] != 0)
for (int j2 = 0; j2 < k; j2++)
trees[i][j]=Math.min(trees[i][j], Math.abs(i-x[j2])+Math.abs(j-y[j2]));
for (int i = 0; i <n; i++)
for (int j = 0; j < m; j++)
if(trees[i][j] > dis)
{
dis=trees[i][j];
xp=i+1;
yp=j+1;
}
PrintWriter out = new PrintWriter("output.txt");
out.printf("%d %d\n", xp ,yp);
out.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner() throws FileNotFoundException {
br = new BufferedReader(new FileReader("input.txt"));
}
String next() throws IOException {
while(st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.awt.Point;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class sdffsdf {
public static void main(String[] args) {
try{
File file = new File("input.txt");
Scanner sc = new Scanner(file);
String s = sc.nextLine();
String[] seperatedd = s.split(" ");
int x = Integer.parseInt(seperatedd[0]);
int y = Integer.parseInt(seperatedd[1]);
int[][] grid = new int[x][y];
for(int i = 0; i < x; i++)
{
for(int j = 0; j < y; j++)
{
grid[i][j] = 0;
}
}
s = sc.nextLine();
int z = Integer.parseInt(s);
LinkedList<Point> BFS = new LinkedList<Point>();
s = sc.nextLine();
String[] seperated = s.split(" ");
for(int i = 0; i < seperated.length; i = i + 2)
{
Point temp = new Point();
temp.x = Integer.parseInt(seperated[i])-1;
temp.y = Integer.parseInt(seperated[i+1])-1;
grid[temp.x][temp.y] = 1;
BFS.addLast(temp);
}
while(!BFS.isEmpty())
{
Point temp = new Point();
temp = BFS.removeFirst();
int k = temp.x;
int l = temp.y;
if(!(l+1 >= y || grid[k][l+1] == 1))
{
Point temp1 = new Point();
temp1.x = k;
temp1.y = l+1;
grid[temp1.x][temp1.y] = 1;
BFS.addLast(temp1);
}
if(!(k+1 >= x || grid[k+1][l] == 1))
{
Point temp1 = new Point();
temp1.x = k+1;
temp1.y = l;
grid[temp1.x][temp1.y] = 1;
BFS.addLast(temp1);
}
if(!(l-1 < 0 || grid[k][l-1] == 1))
{
Point temp1 = new Point();
temp1.x = k;
temp1.y = l-1;
grid[temp1.x][temp1.y] = 1;
BFS.addLast(temp1);
}
if(!(k-1 < 0 || grid[k-1][l] == 1))
{
Point temp1 = new Point();
temp1.x = k-1;
temp1.y = l;
grid[temp1.x][temp1.y] = 1;
BFS.addLast(temp1);
}
if(BFS.isEmpty())
{
try {
File fil = new File("output.txt");
PrintWriter out = new PrintWriter(fil);
int v1 = (int)temp.getX() + 1;
int v2 = (int)temp.getY() + 1;
out.println(v1 + " " + v2);
out.close();
}
catch (Exception e) {}
}
}
}
catch (Exception e) {
System.out.println("nbvnb");
}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.HashSet;
public class FireAgain {
Point[] coordinate;
Queue<Point> q = new LinkedList<>();
// HashSet<Point> vis = new HashSet<>();
boolean[][] vis;
PrintStream out;
int x, y;
boolean distance(Point word1, Point word2) {
if (Math.abs(word1.x - word2.x) == 1 && Math.abs(word1.y - word2.y) == 1)
return false;
if (Math.abs(word1.x - word2.x) == 1 && word1.y == word2.y)
return true;
if (word1.x == word2.x && Math.abs(word1.y - word2.y) == 1)
return true;
return false;
}
void bfs(Point s) {
while (!q.isEmpty()) {
s = q.poll();
Point p = new Point();
p.x = s.x - 1;
p.y = s.y;
if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
if (!vis[p.x][p.y]) {
vis[p.x][p.y] = true;
q.add(p);
}
}
p = new Point();
p.x = s.x + 1;
p.y = s.y;
if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
if (!vis[p.x][p.y]) {
vis[p.x][p.y] = true;
q.add(p);
}
}
p = new Point();
p.x = s.x;
p.y = s.y - 1;
if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
if (!vis[p.x][p.y]) {
vis[p.x][p.y] = true;
q.add(p);
}
}
p = new Point () ;
p.x = s.x ;
p.y = s.y + 1;
if (p.x >= 1 && p.x <= x && p.y >= 1 && p.y <= y) {
if (!vis[p.x][p.y]) {
vis[p.x][p.y] = true ;
q.add(p);
}
}
if (q.size() == 0)
out.print(s.x + " " + s.y);
}
}
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
FireAgain F = new FireAgain();
Scanner in = new Scanner (new FileReader("input.txt"));
F.out = new PrintStream(new File("output.txt"));
F.x = in.nextInt();
F.y = in.nextInt();
int l = 0;
F.vis = new boolean[F.x + 1][F.y + 1];
int k = in.nextInt();
for (int i = 0; i < k; i++) {
Point P = new Point(in.nextInt(), in.nextInt());
F.vis[P.x][P.y] = true; // add in set
F.q.add(P);
}
F.bfs(F.q.peek());
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;
public class QA {
static long MOD = 1000000007;
static boolean b[], b1[], check;
static ArrayList<Integer>[] amp, pa;
static ArrayList<Pair>[] amp1;
static ArrayList<Pair>[][] damp;
static int left[],right[],end[],sum[],dist[],cnt[],start[],color[],parent[],prime[],size[];
static int ans = 0,k;
static int p = 0;
static FasterScanner sc = new FasterScanner(System.in);
//static Queue<Integer> q = new LinkedList<>();
static BufferedWriter log;
static HashSet<Pair> hs;
static HashMap<Pair,Integer> hm;
static PriorityQueue<Integer> pri[];
static ArrayList<Integer>[] level;
static Stack<Integer> st;
static boolean boo[][];
static Pair prr[];
static long parent1[],parent2[],size1[],size2[],arr1[],SUM[],lev[], fibo[];
static int arr[], ver[][];
static private PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws Exception {
new Thread(null, new Runnable() {
public void run() {
try {
soln();
} catch (Exception e) {
System.out.println(e);
}
}
}, "1", 1 << 26).start();
}
private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private static void tr(Object... o) {
if (!oj)
System.out.println(Arrays.deepToString(o));
}
static int dp[][];
static int N,K,T,A,B;
static long time;
static int cost[][];
static boolean b11[];
static HashMap<Integer,Integer> h = new HashMap<>();
static HashSet<Pair> chec;
static long ans1; static long ans2;
static int BLOCK, MAX = 1000001;
static double pi = Math.PI;
static int Arr[], Brr[], pow[], M;
static long fact[] = new long[100000+1];
static HashMap<Integer,Long> hm1;
static HashSet<Integer> hs1[], hs2[];
static String[] str2;
static char[] ch1, ch2;
static int[] s,f,D;
static int tf,ts;
static int see[][] = new int[2050][2050];
static boolean bee[][] = new boolean[2050][2050];
static Queue<Pair> q = new LinkedList<>();
//static PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
public static void soln() throws IOException {
//System.setIn(new FileInputStream("input.txt"));
//System.setOut(new PrintStream("output.txt"));
FasterScanner sc = new FasterScanner(new FileInputStream("input.txt"));//("C:\\Users\\Admin\\Desktop\\QAL2.txt"));
//PrintWriter log1 = new PrintWriter("C:\\Users\\Admin\\Desktop\\input01");
PrintWriter log = new PrintWriter("output.txt");//("C:\\Users\\Admin\\Desktop\\output00");
//log = new BufferedWriter(new OutputStreamWriter(System.out));
int n = sc.nextInt() , m = sc.nextInt();
int k = sc.nextInt();
for(int i = 1; i <= n ; i++) for(int j =1;j<=m;j++) see[i][j]= 100000000;
for(int i = 0; i < k; i++){
int x = sc.nextInt(), y = sc.nextInt();
bee[x][y] = true;
see[x][y] = 0;
q.add(new Pair(x,y));
}
while(!q.isEmpty()){
//System.out.println(q);
int x = q.peek().u, y = q.poll().v;
if(x>1){
see[x-1][y] = min(see[x][y]+1,see[x-1][y]);
if(!bee[x-1][y]) q.add(new Pair(x-1,y));
bee[x-1][y] = true;
}
if(x<n){
see[x+1][y] = min(see[x][y]+1,see[x+1][y]);
if(!bee[x+1][y]) q.add(new Pair(x+1,y));
bee[x+1][y] = true;
}
if(y>1){
see[x][y-1] = min(see[x][y]+1,see[x][y-1]);
if(!bee[x][y-1]) q.add(new Pair(x,y-1));
bee[x][y-1] = true;
}
if(y<m){
see[x][y+1] = min(see[x][y]+1,see[x][y+1]);
if(!bee[x][y+1]) q.add(new Pair(x,y+1));
bee[x][y+1] = true;
}
}
int ans = -1;
Pair temp = null;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(see[i][j]>ans) {
ans = see[i][j];
temp = new Pair(i,j);
}
}
}
log.write(temp.u+" "+temp.v);
log.close();
}
static int min(int a, int b){
if(a>b) return b;
return a;
}
private static double dfs(int cur,int prev){
double r=0,n=0;
for(int i : amp[cur]){
if(i!=prev){
r+=(1+dfs(i,cur));
n++;
}
}
if(n!=0){
r=r/n;
}
return r;
}
static double fa1 = 0;
static int fa = -1;
static long nCr1(int n, int r){
if(n<r) return 0;
return (((fact[n] * modInverse(fact[n-r], MOD))%MOD)*modInverse(fact[r], MOD))%MOD;
}
static class Node{
Node arr[] = new Node[2];
int cnt[] = new int[2];
}
public static class Trie{
Node root;
public Trie(){
root = new Node();
}
public void insert(String x){
Node n = root;
for(int i = 0;i < x.length() ;i++){
int a1 = x.charAt(i)-'0';
if(n.arr[a1]!=null){
n.cnt[a1]++;
n = n.arr[a1];
continue;
}
n.arr[a1] = new Node();
n.cnt[a1]++;
n = n.arr[a1];
}
}
public void delete(String x){
Node n = root;
for(int i = 0;i < x.length() ;i++){
int a1 = x.charAt(i)-'0';
if(n.cnt[a1]==1){
n.arr[a1] = null;
return;
}
else {
n.cnt[a1]--;
n = n.arr[a1];
}
}
}
public long get(String x){
Node n = root;
long ans = 0;
for(int i = 0;i < x.length() ;i++){
int a1 = '1' - x.charAt(i);
if(n.arr[a1]!=null){
ans += Math.pow(2, 30-i);
n = n.arr[a1];
}
else n = n.arr[1-a1];
// System.out.println(ans);
}
return ans;
}
}
public static class FenwickTree {
int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates
public FenwickTree(int size) {
array = new int[size + 1];
}
public int rsq(int ind) {
assert ind > 0;
int sum = 0;
while (ind > 0) {
sum += array[ind];
//Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number
ind -= ind & (-ind);
}
return sum;
}
public int rsq(int a, int b) {
assert b >= a && a > 0 && b > 0;
return rsq(b) - rsq(a - 1);
}
public void update(int ind, int value) {
assert ind > 0;
while (ind < array.length) {
array[ind] += value;
//Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number
ind += ind & (-ind);
}
}
public int size() {
return array.length - 1;
}
}
static double power(double x, long y)
{
if (y == 0)
return 1;
double p = power(x, y/2);
p = (p * p);
return (y%2 == 0)? p : (x * p);
}
static int Dfs(int x, int val){
b[x] = true;
for(int p:hs2[x]){
if(!b[p]){
if(!hs1[x].contains(p)) val++;
val += Dfs(p,0);
}
}
return val;
}
static long nCr(int n, int r){
if(n<r) return 0;
else return (((fact[n]*modInverse(fact[r], MOD))%MOD)*modInverse(fact[n-r], MOD))%MOD;
}
static void dfs1(int x, int p){
arr1[x] += lev[x];
for(int v:amp[x]){
if(v!=p){
dfs1(v,x);
}
}
}
static void bfs(int x){
}
public static void seive(int n){
b = new boolean[(n+1)];
Arrays.fill(b, true);
b[1] = true;
for(int i = 2;i*i<=n;i++){
if(b[i]){
for(int p = 2*i;p<=n;p+=i){
b[p] = false;
}
}
}
/*for(int i = 2;i<=n;i++){
if(b[i]) prime[i] = i;
}*/
}
static class Graph{
int vertex;
int weight;
Graph(int v, int w){
vertex = v;
weight = w;
}
}
static class Pair implements Comparable<Pair> {
int u;
int v;
int ans;
public Pair(){
u = 0;
v = 0;
}
public Pair(int u, int v) {
this.u = u;
this.v = v;
}
public int hashCode() {
return Objects.hash();
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return ((u == other.u && v == other.v && ans == other.ans));
}
public int compareTo(Pair other) {
//return Double.compare(ans, other.ans);
return Long.compare(u, other.u);
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
public static void buildGraph(int n){
for(int i =0;i<n;i++){
int x = sc.nextInt()-1, y = sc.nextInt()-1;
amp[x].add(y);
amp[y].add(x);
}
}
public static int getParent(long x){
while(parent[(int) x]!=x){
parent[ (int) x] = parent[(int) parent[ (int) x]];
x = parent[ (int) x];
}
return (int) x;
}
static long min(long a, long b, long c){
if(a<b && a<c) return a;
if(b<c) return b;
return c;
}
/*
static class Pair3{
int x, y ,z;
Pair3(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
}*/
static void KMPSearch(String pat, String txt)
{
int M = pat.length();
int N = txt.length();
// create lps[] that will hold the longest
// prefix suffix values for pattern
int lps[] = new int[M];
int j = 0; // index for pat[]
// Preprocess the pattern (calculate lps[]
// array)
computeLPSArray(pat,M,lps);
int i = 0; // index for txt[]
while (i < N)
{
if (pat.charAt(j) == txt.charAt(i))
{
j++;
i++;
}
if (j == M)
{
// parent.add((i-j));
j = lps[j-1];
}
// mismatch after j matches
else if (i < N && pat.charAt(j) != txt.charAt(i))
{
// Do not match lps[0..lps[j-1]] characters,
// they will match anyway
if (j != 0)
j = lps[j-1];
else
i = i+1;
}
}
}
static void computeLPSArray(String pat, int M, int lps[])
{
// length of the previous longest prefix suffix
int len = 0;
int i = 1;
lps[0] = 0; // lps[0] is always 0
// the loop calculates lps[i] for i = 1 to M-1
while (i < M)
{
if (pat.charAt(i) == pat.charAt(len))
{
len++;
lps[i] = len;
i++;
}
else // (pat[i] != pat[len])
{
// This is tricky. Consider the example.
// AAACAAAA and i = 7. The idea is similar
// to search step.
if (len != 0)
{
len = lps[len-1];
// Also, note that we do not increment
// i here
}
else // if (len == 0)
{
lps[i] = len;
i++;
}
}
}
}
private static void permutation(String prefix, String str) {
int n = str.length();
if (n == 0); //hs.add(prefix);
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
}
}
public static void buildTree(int n){
int arr[] = sc.nextIntArray(n);
for(int i = 0;i<n;i++){
int x = arr[i]-1;
amp[i+1].add(x);
amp[x].add(i+1);
}
}
static class SegmentTree {
boolean st[];
boolean lazy[];
SegmentTree(int n) {
int size = 4 * n;
st = new boolean[size];
Arrays.fill(st, true);
lazy = new boolean[size];
Arrays.fill(lazy, true);
//build(0, n - 1, 1);
}
/*long[] build(int ss, int se, int si) {
if (ss == se) {
st[si][0] = 1;
st[si][1] = 1;
st[si][2] = 1;
return st[si];
}
int mid = (ss + se) / 2;
long a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se,
si * 2 + 1);
long ans[] = new long[3];
if (arr[mid] < arr[mid + 1]) {
ans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0]));
if (a1[1] == (mid - ss + 1))
ans[0] = ans[1];
else
ans[0] = a1[0];
if (a2[2] == (se - mid))
ans[2] = ans[1];
else
ans[2] = a2[2];
} else {
ans[1] = Math.max(a1[1], a2[1]);
ans[0] = a1[0];
ans[2] = a2[2];
}
st[si] = ans;
return st[si];
}*/
void update(int si, int ss, int se, int idx, long x) {
if (ss == se) {
//arr[idx] += val;
st[si]=false;
}
else {
int mid = (ss + se) / 2;
if(ss <= idx && idx <= mid)
{
update(2*si, ss, mid, idx, x);
}
else
{ update(2*si+1, mid+1, se, idx, x);
}
st[si] = st[2*si]|st[2*si+1];
}
}
/*boolean get(int qs, int qe, int ss, int se, int si){
if(qs>se || qe<ss) return 0;
if (qs <= ss && qe >= se) {
return st[si];
}
int mid = (ss+se)/2;
return get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1);
}*/
void updateRange(int node, int start, int end, int l, int r, boolean val)
{
if(!lazy[node])
{
// This node needs to be updated
st[node] = lazy[node]; // Update it
if(start != end)
{
lazy[node*2] = lazy[node]; // Mark child as lazy
lazy[node*2+1] = lazy[node]; // Mark child as lazy
}
lazy[node] = true; // Reset it
}
if(start > end || start > r || end < l) // Current segment is not within range [l, r]
return;
if(start >= l && end <= r)
{
// Segment is fully within range
st[node] = val;
if(start != end)
{
// Not leaf node
lazy[node*2] = val;
lazy[node*2+1] = val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node*2, start, mid, l, r, val); // Updating left child
updateRange(node*2 + 1, mid + 1, end, l, r, val); // Updating right child
st[node] = st[node*2] | st[node*2+1]; // Updating root with max value
}
boolean queryRange(int node, int start, int end, int l, int r)
{
if(start > end || start > r || end < l)
return false; // Out of range
if(!lazy[node])
{
// This node needs to be updated
st[node] = lazy[node]; // Update it
if(start != end)
{
lazy[node*2] = lazy[node]; // Mark child as lazy
lazy[node*2+1] = lazy[node]; // Mark child as lazy
}
lazy[node] = true; // Reset it
}
if(start >= l && end <= r) // Current segment is totally within range [l, r]
return st[node];
int mid = (start + end) / 2;
boolean p1 = queryRange(node*2, start, mid, l, r); // Query left child
boolean b = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
return (p1 | b);
}
void print() {
for (int i = 0; i < st.length; i++) {
System.out.print(st[i]+" ");
}
System.out.println();
}
}
static int convert(int x){
int cnt = 0;
String str = Integer.toBinaryString(x);
//System.out.println(str);
for(int i = 0;i<str.length();i++){
if(str.charAt(i)=='1'){
cnt++;
}
}
int ans = (int) Math.pow(3, 6-cnt);
return ans;
}
static class Node2{
Node2 left = null;
Node2 right = null;
Node2 parent = null;
int data;
}
static boolean check(char ch[][], int i, int j){
if(ch[i][j]=='O') return false;
char c = ch[i][j];
ch[i][j] = 'X';
if(c=='X'){
if(i>=4){
int x = 0;
int l = 0;
for(x = 0;x<=4;x++){
if(ch[i-x][j]!='X'){ if(ch[i-x][j]!='.') break;else l++;}
}
if(x==5 && l<=1) return true;
l = 0;
if(j>=4){
for(x = 0;x<=4;x++){
if(ch[i-x][j-x]!='X'){ if(ch[i-x][j-x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
l =0;
for(x = 0;x<=4;x++){
if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
}
if(j<=5){
l = 0;
for(x = 0;x<=4;x++){
if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
l = 0;
for(x = 0;x<=4;x++){
if(ch[i-x][j+x]!='X'){ if(ch[i-x][j+x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
}
}
if(i<=5){
int x = 0;
int l = 0;
for(x = 0;x<=4;x++){
if(ch[i+x][j]!='X'){ if(ch[i+x][j]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
l = 0;
if(j>=4){
for(x = 0;x<=4;x++){
if(ch[i+x][j-x]!='X'){ if(ch[i+x][j-x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
l =0;
for(x = 0;x<=4;x++){
if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
}
if(j<=5){
l = 0;
for(x = 0;x<=4;x++){
if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
l = 0;
for(x = 0;x<=4;x++){
if(ch[i+x][j+x]!='X'){ if(ch[i+x][j+x]!='.') break; else l++;}
}
if(x==5 && l<=1) return true;
}
}
}
else{
if(i>=4){
int x = 0;
int l = 0;
for(x = 0;x<=4;x++){
if(ch[i-x][j]!='X'){ if(ch[i-x][j]!='.') break;else l++;}
}
if(x==5 && l<=0) return true;
l = 0;
if(j>=4){
for(x = 0;x<=4;x++){
if(ch[i-x][j-x]!='X'){ if(ch[i-x][j-x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
l =0;
for(x = 0;x<=4;x++){
if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
}
if(j<=5){
l = 0;
for(x = 0;x<=4;x++){
if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
l = 0;
for(x = 0;x<=4;x++){
if(ch[i-x][j+x]!='X'){ if(ch[i-x][j+x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
}
}
if(i<=5){
int x = 0;
int l = 0;
for(x = 0;x<=4;x++){
if(ch[i+x][j]!='X'){ if(ch[i+x][j]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
l = 0;
if(j>=4){
for(x = 0;x<=4;x++){
if(ch[i+x][j-x]!='X'){ if(ch[i+x][j-x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
l =0;
for(x = 0;x<=4;x++){
if(ch[i][j-x]!='X'){ if(ch[i][j-x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
}
if(j<=5){
l = 0;
for(x = 0;x<=4;x++){
if(ch[i][j+x]!='X'){ if(ch[i][j+x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
l = 0;
for(x = 0;x<=4;x++){
if(ch[i+x][j+x]!='X'){ if(ch[i+x][j+x]!='.') break; else l++;}
}
if(x==5 && l<=0) return true;
}
}
}
ch[i][j] = c;
return false;
}
static class BinarySearchTree{
Node2 root = null;
int height = 0;
int max = 0;
int cnt = 1;
ArrayList<Integer> parent = new ArrayList<>();
HashMap<Integer, Integer> hm = new HashMap<>();
public void insert(int x){
Node2 n = new Node2();
n.data = x;
if(root==null){
root = n;
}
else{
Node2 temp = root,temb = null;
while(temp!=null){
temb = temp;
if(x>temp.data) temp = temp.right;
else temp = temp.left;
}
if(x>temb.data) temb.right = n;
else temb.left = n;
n.parent = temb;
parent.add(temb.data);
}
}
public Node2 getSomething(int x, int y, Node2 n){
if(n.data==x || n.data==y) return n;
else if(n.data>x && n.data<y) return n;
else if(n.data<x && n.data<y) return getSomething(x,y,n.right);
else return getSomething(x,y,n.left);
}
public Node2 search(int x,Node2 n){
if(x==n.data){
max = Math.max(max, n.data);
return n;
}
if(x>n.data){
max = Math.max(max, n.data);
return search(x,n.right);
}
else{
max = Math.max(max, n.data);
return search(x,n.left);
}
}
public int getHeight(Node2 n){
if(n==null) return 0;
height = 1+ Math.max(getHeight(n.left), getHeight(n.right));
return height;
}
}
static long findDiff(long[] arr, long[] brr, int m){
int i = 0, j = 0;
long fa = 1000000000000L;
while(i<m && j<m){
long x = arr[i]-brr[j];
if(x>=0){
if(x<fa) fa = x;
j++;
}
else{
if((-x)<fa) fa = -x;
i++;
}
}
return fa;
}
public static long max(long x, long y, long z){
if(x>=y && x>=z) return x;
if(y>=x && y>=z) return y;
return z;
}
static long modInverse(long a, long mOD2){
return power(a, mOD2-2, mOD2);
}
static long power(long x, long y, long m)
{
if (y == 0)
return 1;
long p = power(x, y/2, m) % m;
p = (p * p) % m;
return (y%2 == 0)? p : (x * p) % m;
}
static long d,x,y;
public static void extendedEuclidian(long a, long b){
if(b == 0) {
d = a;
x = 1;
y = 0;
}
else {
extendedEuclidian(b, a%b);
int temp = (int) x;
x = y;
y = temp - (a/b)*y;
}
}
public static long gcd(long n, long m){
if(m!=0) return gcd(m,n%m);
else return n;
}
static BufferedReader reader;
static StringTokenizer tokenizer;
static PrintWriter writer;
static class FasterScanner {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public FasterScanner(InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n) {
long a[] = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public String readString() {
int c = snext();
while (isSpaceChar(c)) {
c = snext();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import javax.annotation.processing.SupportedSourceVersion;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(new FileReader("input.txt")); // new InputReader(inputStream);
PrintWriter out = new PrintWriter("output.txt"); //new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(in, out);
out.close();
}
private static class TaskB {
static final long max = 1000000000000000000L;
static final double eps = 0.0000001;
static final long mod = 1000000007;
static int N, M, K;
static long X, Y;
static boolean F[][][];
static int D[][];
void solve(InputReader in, PrintWriter out) throws IOException {
N = in.nextInt();
M = in.nextInt();
K = in.nextInt();
F = new boolean[K][N][M];
D = new int[N][M];
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
D[i][j] = Integer.MAX_VALUE;
List<Pair> list = new ArrayList<>();
for (int i = 0; i < K; i++) {
list.add(new Pair(in.nextInt() - 1, in.nextInt() - 1));
}
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
for (int k = 0; k < K; k++)
D[i][j] = Math.min(D[i][j], Math.abs(list.get(k).X - i) + Math.abs(list.get(k).Y - j));
int res = Integer.MIN_VALUE;
for (int j = 0; j < N; j++)
for (int k = 0; k < M; k++)
if (D[j][k] > res) {
X = j + 1;
Y = k + 1;
res = D[j][k];
}
out.println(X + " " + Y);
}
class Pair {
int X, Y;
Pair(int X, int Y) {
this.X = X;
this.Y = Y;
}
}
long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
boolean isPrime(long n) {
if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
return false;
for (long i = 5, j = 2; i * i <= n; i += j, j = 6 - j)
if (n % i == 0)
return false;
return true;
}
boolean isEqual(double A, double B) {
return Math.abs(A - B) < eps;
}
double dist(double X1, double Y1, double X2, double Y2) {
return Math.sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
}
boolean nextPer(int[] data) {
int i = data.length - 1;
while (i > 0 && data[i] < data[i - 1]) {
i--;
}
if (i == 0) {
return false;
}
int j = data.length - 1;
while (data[j] < data[i - 1]) {
j--;
}
int temp = data[i - 1];
data[i - 1] = data[j];
data[j] = temp;
Arrays.sort(data, i, data.length);
return true;
}
long pow(long A, long B, long MOD) {
if (B == 0) {
return 1;
}
if (B == 1) {
return A;
}
long val = pow(A, B / 2, MOD);
if (B % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * A % MOD) % MOD;
}
}
}
private static class InputReader {
StringTokenizer st;
BufferedReader br;
public InputReader(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public InputReader(FileReader s) throws FileNotFoundException {
br = new BufferedReader(s);
}
public String next() {
while (st == null || !st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
public boolean ready() {
try {
return br.ready();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
public class C {
public static void main(String[] args) throws Exception {
final int fuck = 2001;
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = in.nextInt(), m = in.nextInt();
int[] D = new int[ fuck*fuck ], Q = new int[ fuck*(fuck + 1) ],
dx = new int[] { 1, -1, 0, 0},
dy = new int[] { 0, 0, -1, 1};
Arrays.fill(D, -1);
int H = -1, T = 0;
int k = in.nextInt(), ans = 0;
for(int i = 0; i < k; ++i) {
int x = in.nextInt(), y = in.nextInt();
D[x * fuck + y] = 0;
++H; H %= Q.length;
ans = Q[H] = x * fuck + y;
}
while(H >= T) {
int idx = Q[T++]; T %= Q.length;
int x = idx / fuck, y = idx % fuck;
for(int i = 0; i < 4; ++i) {
int wtf = (dx[i] + x) * fuck + (dy[i] + y);
if(dx[i] + x <= n && dx[i] + x >= 1 && dy[i] + y <= m && dy[i] + y >= 1 && D[wtf] == -1) {
D[wtf] = D[idx] + 1;
++H; H %= Q.length;
Q[H] = wtf;
if(D[wtf] >= D[ans])
ans = wtf;
}
}
}
out.println((ans / fuck) + " " + (ans % fuck));
out.close();
in.close();
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.math.*;
import java.util.*;
import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;
public class C35
{
public static int mod = 1000000007;
public static long INF = (1L << 60);
static int n,m;
static class Pair
{
int x,y;
Pair(int x,int y)
{
this.x=x;
this.y=y;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + x;
result = prime * result + y;
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair other = (Pair) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
}
static boolean[][] burned;
static int[] dx={-1,0,1,0};
static int[] dy={0,-1,0,1};
static boolean isvalid(int x,int y)
{
return x>=0&&x<n&&y>=0&&y<m;
}
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner("input.txt");
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
n=in.nextInt();
m=in.nextInt();
burned=new boolean[n][m];
int k=in.nextInt();
Set<Pair> set=new HashSet<Pair>();
Pair prev=null;
for(int i=0;i<k;i++)
{
int x=in.nextInt();
int y=in.nextInt();
burned[x-1][y-1]=true;
set.add(prev=new Pair(x-1, y-1));
}
while(!set.isEmpty())
{
Set<Pair> tempset=new HashSet<>();
for(Pair p : set)
{
int x=p.x;
int y=p.y;
prev=p;
for(int i=0;i<4;i++)
{
if(isvalid(x+dx[i], y+dy[i])&&!burned[x+dx[i]][y+dy[i]])
{
tempset.add(new Pair(x+dx[i], y+dy[i]));
burned[x+dx[i]][y+dy[i]]=true;
}
}
}
set=tempset;
}
out.printf("%d %d\n",(prev.x+1),(prev.y+1));
out.close();
}
public static long pow(long x, long n)
{
long res = 1;
for (long p = x; n > 0; n >>= 1, p = (p * p))
{
if ((n & 1) != 0)
{
res = (res * p);
}
}
return res;
}
public static long pow(long x, long n, long mod)
{
long res = 1;
for (long p = x; n > 0; n >>= 1, p = (p * p) % mod)
{
if ((n & 1) != 0)
{
res = (res * p % mod);
}
}
return res;
}
public static long gcd(long n1, long n2)
{
long r;
while (n2 != 0)
{
r = n1 % n2;
n1 = n2;
n2 = r;
}
return n1;
}
public static long lcm(long n1, long n2)
{
long answer = (n1 * n2) / (gcd(n1, n2));
return answer;
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(String s) throws FileNotFoundException{ br = new BufferedReader(new FileReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
//package c;
import java.util.*;
import java.io.*;
public class Main {
int n,m;
int d[][];
Queue<int[]> q = new LinkedList<int[]>();
int cur[];
public void run() throws Exception{
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
n = in.nextInt();
m = in.nextInt();
int k = in.nextInt();
d = new int[n][m];
for(int i=0;i<n;i++) Arrays.fill(d[i], Integer.MAX_VALUE/2);
for(int i=0;i<k;i++){
int x = in.nextInt()-1;
int y = in.nextInt()-1;
d[x][y] = 0;
q.add(new int[]{x,y});
}
while(q.size() > 0){
cur = q.poll();
int x = cur[0];
int y = cur[1];
add(x, y+1);
add(x+1, y);
add(x-1, y);
add(x, y-1);
}
int max = 0;
int x = 0;
int y = 0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if (max < d[i][j]){
max = d[i][j];
x = i;
y = j;
}
out.println((x+1) + " " + (y+1));
out.close();
}
private void add(int x, int y){
if (x < 0 || y < 0) return;
if (x >=n || y >=m) return;
if (d[x][y] > d[cur[0]][cur[1]] + 1){
d[x][y] = d[cur[0]][cur[1]] + 1;
q.add(new int[]{x,y});
}
}
public static void main(String[] args) throws Exception{
new Main().run();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solution {
BufferedReader in;
StringTokenizer st;
PrintWriter out;
int n, m, k;
int[] x, y;
char[] qx = new char[4000000], qy = new char[4000000];
int b, e;
char[][] d;
int[] dx = { -1, 0, 1, 0 }, dy = { 0, -1, 0, 1 };
void bfs() {
b = e = 0;
for (int i = 0; i < d.length; i++) {
Arrays.fill(d[i], (char)(1 << 14));
}
for (int i = 0; i < k; ++i) {
qx[e] = (char) x[i];
qy[e++] = (char) y[i];
d[x[i]][y[i]] = 0;
}
for (; b < e; ++b) {
int x = qx[b];
int y = qy[b];
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= 0 && nx < n && ny >= 0 && ny < m)
if (d[nx][ny] > d[x][y] + 1) {
d[nx][ny] = (char) (d[x][y] + 1);
qx[e] = (char) nx;
qy[e++] = (char) ny;
}
}
}
}
void solve() throws IOException {
n = ni();
m = ni();
k = ni();
x = new int[k];
y = new int[k];
for (int i = 0; i < k; ++i) {
x[i] = ni() - 1;
y[i] = ni() - 1;
}
d = new char[n][m];
bfs();
int x = -1, y = -1, last = -1;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
if (d[i][j] > last) {
last = d[i][j];
x = i;
y = j;
}
++x;
++y;
out.println(x + " " + y);
}
public Solution() throws IOException {
Locale.setDefault(Locale.US);
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
solve();
in.close();
out.close();
}
String nline() throws IOException {
return in.readLine();
}
String ns() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nline());
}
return st.nextToken();
}
int ni() throws IOException {
return Integer.valueOf(ns());
}
long nl() throws IOException {
return Long.valueOf(ns());
}
double nd() throws IOException {
return Double.valueOf(ns());
}
public static void main(String[] args) throws IOException {
new Solution();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintStream;
import java.util.Scanner;
public class P35C {
int n, m;
int [][]fire;
public P35C() throws FileNotFoundException {
Scanner in = new Scanner(new FileReader("input.txt"));
n = in.nextInt();
m = in.nextInt();
int k = in.nextInt();
fire = new int[k][2];
for (int i = 0; i < k; i++){
fire[i][0] = in.nextInt();
fire[i][1] = in.nextInt();
}
in.close();
int []last = new int[2];
int lastBurn = -1;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
int burn = Integer.MAX_VALUE;
for (int l = 0; l < k; l++){
int burnAux = dist(i, j, fire[l][0], fire[l][1]);
burn = Math.min(burn, burnAux);
}
if(burn >= lastBurn){
lastBurn = burn;
last[0] = i;
last[1] = j;
}
}
}
PrintStream out = new java.io.PrintStream( "output.txt" );
out.print(last[0] + " " + last[1]);
out.close();
}
int dist(int x1, int y1, int x2, int y2){
return Math.abs(x2 - x1) + Math.abs(y2 - y1);
}
public static void main (String []args) throws FileNotFoundException{
new P35C();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
/**
* Created by IntelliJ IDEA.
* User: Taras_Brzezinsky
* Date: 9/16/11
* Time: 1:27 PM
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.StringTokenizer;
public class TaskC extends Thread {
public TaskC() {
try {
this.input = new BufferedReader(new FileReader("input.txt"));
this.output = new PrintWriter("output.txt");
this.setPriority(Thread.MAX_PRIORITY);
} catch (Throwable e) {
System.exit(666);
}
}
private void solve() throws Throwable {
int n = nextInt();
int m = nextInt();
int k = nextInt();
Queue<Integer> qX = new ArrayDeque<Integer>();
Queue<Integer> qY = new ArrayDeque<Integer>();
boolean [][]was = new boolean[n][m];
for (int i = 0; i < k; ++i) {
int x = nextInt() - 1, y = nextInt() - 1;
qX.add(x);
qY.add(y);
was[x][y] = true;
}
int lastX = -1, lastY = -1;
while (!qX.isEmpty()) {
lastX = qX.poll();
lastY = qY.poll();
for (int i = 0; i < dx.length; ++i) {
int nextX = lastX + dx[i], nextY = lastY + dy[i];
if (nextX < n && nextY < m && nextX >= 0 && nextY >= 0 && !was[nextX][nextY]) {
qX.add(nextX);
qY.add(nextY);
was[nextX][nextY] = true;
}
}
}
++lastX;
++lastY;
output.println(lastX + " " + lastY);
}
public void run() {
try {
solve();
} catch (Throwable e) {
System.err.println(e.getMessage());
e.printStackTrace();
System.exit(666);
} finally {
output.flush();
output.close();
}
}
public static void main(String[] args) {
new TaskC().start();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
private double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
private String nextToken() throws IOException {
while (tokens == null || !tokens.hasMoreTokens()) {
tokens = new StringTokenizer(input.readLine());
}
return tokens.nextToken();
}
static final int PRIME = 3119;
static final int[]dx = {1, -1, 0, 0}, dy = {0, 0, -1, 1};
private BufferedReader input;
private PrintWriter output;
private StringTokenizer tokens = null;
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner scn = new Scanner(new File("input.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("output.txt"));
int r = scn.nextInt();
int c = scn.nextInt();
int[][] a = new int[r][c];
for(int[] i: a)
Arrays.fill(i, 1<<30);
int k = scn.nextInt();
Queue<State> q = new LinkedList<State>();
for(int l = 0; l < k; l++){
int i = scn.nextInt()-1;
int j = scn.nextInt()-1;
a[i][j] = 0;
q.add(new State(i, j, 0));
}
while(!q.isEmpty()){
State st = q.poll();
a[st.i][st.j] = st.c;
for(int d = 0; d < 4; d++){
int ii = st.i + di[d];
int jj = st.j + dj[d];
if(ii < 0 || ii >= r || jj < 0 || jj >= c)continue;
if(a[ii][jj] != 1 << 30)continue;
a[ii][jj] = st.c+1;
q.add(new State(ii, jj, st.c+1));
}
}
int max = 0;
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
max = Math.max(max, a[i][j]);
for(int i = 0; i < r; i++)
for(int j = 0; j < c; j++)
if(a[i][j] == max){
// System.out.println(i+1 + " " + (j+1));
out.write((i+1)+" "+(j+1));
out.newLine();
out.close();
return;
}
}
static int[] di = {0, 0, -1, 1};
static int[] dj = {1, -1, 0, 0};
}
class State{
int i, j, c;
public State(int ii, int ji, int ci){
i = ii;
j = ji;
c = ci;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class CF_35C {
public static void main(String[] args) throws IOException{
BufferedReader f = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
StringTokenizer st1 = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st1.nextToken());
int m = Integer.parseInt(st1.nextToken());
boolean[][] visited = new boolean[n][m];
int k = Integer.parseInt(f.readLine());
LinkedList<state1> ll = new LinkedList<state1>();
StringTokenizer st = new StringTokenizer(f.readLine());
for(int i = 0; i < k; i++) {
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
ll.add(new state1(x - 1, y - 1));
visited[x - 1][y - 1] = true;
}
int lastx = 1;
int lasty = 1;
while(!ll.isEmpty()) {
state1 focus = ll.remove();
lastx = focus.x+1;
lasty = focus.y+1;
//System.out.println(lastx + " " + lasty);
visited[focus.x][focus.y] = true;
if(focus.x+1 < n && !visited[focus.x+1][focus.y]) {
ll.add(new state1(focus.x+1, focus.y));
visited[focus.x+1][focus.y] = true;
}
if(focus.x-1 >= 0 && !visited[focus.x-1][focus.y]) {
ll.add(new state1(focus.x-1, focus.y));
visited[focus.x-1][focus.y] = true;
}
if(focus.y+1 < m && !visited[focus.x][focus.y+1]) {
ll.add(new state1(focus.x, focus.y+1));
visited[focus.x][focus.y+1] = true;
}
if(focus.y-1 >= 0 && !visited[focus.x][focus.y-1]) {
ll.add(new state1(focus.x, focus.y-1));
visited[focus.x][focus.y-1] = true;
}
}
out.println(lastx + " " + lasty);
out.close();
}
}
class state1 {
int x, y;
state1(int x, int y) {
this.x = x; this.y = y;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class ProblemD {
static int n;
static int m;
static boolean[][] fire;
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(new File("input.txt"));
n = sc.nextInt();
m = sc.nextInt();
int k = sc.nextInt();
fire = new boolean[n][m];
Queue<Pos> q = new LinkedList<Pos>();
for (int i = 0; i < k; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
q.add(new Pos(x - 1, y - 1));
fire[x - 1][y - 1] = true;
}
int[] di = new int[] { 1, -1, 0, 0 };
int[] dj = new int[] { 0, 0, 1, -1};
Pos last = null;
while (q.size() > 0) {
Pos pos = q.poll();
last = pos;
for (int kk = 0; kk < 4; kk++) {
int ni = pos.i + di[kk];
int nj = pos.j + dj[kk];
if (ni >= 0 && nj >= 0 && ni < n && nj < m) {
if (!fire[ni][nj]) {
fire[ni][nj] = true;
q.add(new Pos(ni, nj));
}
}
}
}
PrintWriter out = new PrintWriter(new File("output.txt"));
out.println((last.i + 1) + " " + (last.j + 1));
out.flush();
out.close();
}
}
class Pos {
int i, j;
public Pos(int i, int j) {
super();
this.i = i;
this.j = j;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + i;
result = prime * result + j;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pos other = (Pos) obj;
if (i != other.i)
return false;
if (j != other.j)
return false;
return true;
}
};
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.ArrayDeque;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Zyflair Griffane
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream;
try {
inputStream = new FileInputStream("input.txt");
} catch (IOException e) {
throw new RuntimeException(e);
}
OutputStream outputStream;
try {
outputStream = new FileOutputStream("output.txt");
} catch (IOException e) {
throw new RuntimeException(e);
}
PandaScanner in = new PandaScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
C solver = new C();
solver.solve(1, in, out);
out.close();
}
}
class C {
final int dx[] = { -1, 0, 1, 0};
final int dy[] = { 0, -1, 0, 1};
final int SHIFT = 15;
final int COLUMN_MASK = (1 << SHIFT) - 1;
public void solve(int testNumber, PandaScanner in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
boolean burning[][] = new boolean[n][m];
int k = in.nextInt();
ArrayDeque<Integer> q = new ArrayDeque<>();
for (int i = 0; i < k; i++) {
int x = in.nextInt() - 1;
int y = in.nextInt() - 1;
burning[x][y] = true;
q.add((x << SHIFT) + y);
}
int last = 0;
while (!q.isEmpty()) {
last = q.poll();
int x = last >> SHIFT;
int y = last & COLUMN_MASK;
for (int d = 0; d < 4; d++) {
int nx = x + dx[d];
int ny = y + dy[d];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && !burning[nx][ny]) {
burning[nx][ny] = true;
q.add((nx << SHIFT) + ny);
}
}
}
out.printf("%d %d\n", (last >> SHIFT) + 1, (last & COLUMN_MASK) + 1);
}
}
class PandaScanner {
public BufferedReader br;
public StringTokenizer st;
public InputStream in;
public PandaScanner(InputStream in) {
br = new BufferedReader(new InputStreamReader(this.in = in));
}
public String nextLine() {
try {
return br.readLine();
}
catch (Exception e) {
return null;
}
}
public String next() {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine().trim());
return next();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.util.ArrayList;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.*;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException
{
Scanner sc = new Scanner(new File("input.txt"));
int n = sc.nextInt();
int m =sc.nextInt();
sc.nextLine();
int k =sc.nextInt();
int les[][] = new int[n][m];
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
//sc.nextLine();
ArrayList<Integer[]> list = new ArrayList();
sc.nextLine();
for(int i = 0;i<k;i++)
{
Integer[] ii = new Integer[2];
ii[0] = sc.nextInt()-1;
ii[1] = sc.nextInt()-1;
list.add(ii);
}
sc.close();
int maxr = 0;
int maxi = 0;
int maxj = 0;
for(int i = 0;i<n;i++)
{
for(int j = 0;j<m;j++)
{
int minr = 100000;
int mini = 0;
int minj = 0;
for(int f = 0;f<k;f++)
{
Integer[] ii = list.get(f);
int ww = Math.abs(ii[0] - i);
int hh = Math.abs(ii[1] - j);
int r = ww+hh;
if(r<minr)
{
minr = r;
mini=i;
minj=j;
}
}
if(maxr<minr&&minr<100000)
{
maxi = mini;
maxj = minj;
maxr = minr;
}
}
}
out.print((maxi+1)+" "+(maxj+1));
out.close();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
public class C{
public static void main(String args[]) throws Exception{
Scanner in = new Scanner(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int N = in.nextInt();
int M = in.nextInt();
int K = in.nextInt();
int[] X = new int[K], Y = new int[K];
for (int i = 0; i < K; i++){
X[i] = in.nextInt();
Y[i] = in.nextInt();
}
int d = -1;
int a = -1; int b = -1;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++){
int h = Integer.MAX_VALUE;
for (int p = 0; p < K; p++)
h = Math.min(h,Math.abs(i-X[p]) + Math.abs(j-Y[p]));
if (h > d){
d = h; a = i; b = j;
}
}
out.print(a + " " + b);
out.close();
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class Main implements Runnable {
public void _main() throws IOException {
int height = nextInt();
int width = nextInt();
int k = nextInt();
int[] r = new int[k];
int[] c = new int[k];
for (int i = 0; i < k; i++) {
r[i] = nextInt() - 1;
c[i] = nextInt() - 1;
}
int res = 0, R = r[0], C = c[0];
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++) {
int cur = Integer.MAX_VALUE;
for (int z = 0; z < k; z++)
cur = Math.min(cur, Math.abs(i - r[z]) + Math.abs(j - c[z]));
if (res < cur) {
res = cur;
R = i;
C = j;
}
}
out.print((R + 1) + " " + (C + 1));
}
private BufferedReader in;
private PrintWriter out;
private StringTokenizer st;
private String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(next());
}
private long nextLong() throws IOException {
return Long.parseLong(next());
}
private double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public static void main(String[] args) {
new Thread(new Main()).start();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
_main();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(202);
}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
public class C
{
public static void main(String[] args) throws Exception
{
new C(new Scanner(new File("input.txt")), new PrintWriter("output.txt"));
}
int oo = 987654321;
int W, H;
public C(Scanner in, PrintWriter out)
{
W = in.nextInt();
H = in.nextInt();
int[][] grid = new int[W][H];
for (int[] gri : grid)
Arrays.fill(gri, oo);
ArrayDeque<Node> q = new ArrayDeque<Node>();
int K = in.nextInt();
for (int u=0; u<K; u++)
{
q.add(new Node(in.nextInt()-1, in.nextInt()-1, 0));
while (q.size() > 0)
{
Node cur = q.poll();
if (grid[cur.x][cur.y] <= cur.d)
continue;
grid[cur.x][cur.y] = cur.d;
if (cur.x+1<W)
q.add(new Node(cur.x+1, cur.y, cur.d+1));
if (cur.x>0)
q.add(new Node(cur.x-1, cur.y, cur.d+1));
if (cur.y+1<H)
q.add(new Node(cur.x, cur.y+1, cur.d+1));
if (cur.y>0)
q.add(new Node(cur.x, cur.y-1, cur.d+1));
}
}
int res = 0;
for (int j=0; j<H; j++)
for (int i=0; i<W; i++)
res = Math.max(res, grid[i][j]);
for (int j=0; j<H; j++)
for (int i=0; i<W; i++)
if (res == grid[i][j])
{
out.printf("%d %d%n", i+1, j+1);
out.close();
return;
}
}
}
class Node
{
int x, y, d;
public Node(int xx, int yy, int dd)
{
x=xx; y=yy; d=dd;
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.Queue;
public class Solution{
static int[] dx = {1,-1,0,0};
static int[] dy = {0,0,1,-1};
static Queue<Pair> q ;
static boolean[][] visited ;
static Pair result = new Pair(0,0);
static int n,m,k;
public static void main(String[] args){
try(BufferedReader in = new BufferedReader(new FileReader("input.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("output.txt")))
{
StringTokenizer s = new StringTokenizer(in.readLine());
n = Integer.parseInt(s.nextToken());
m = Integer.parseInt(s.nextToken());
k = Integer.parseInt(in.readLine());
visited = new boolean[n][m];
q = new LinkedList <>();
s = new StringTokenizer(in.readLine());
for(int i=0;i<k;i++){
int x = Integer.parseInt(s.nextToken());
int y = Integer.parseInt(s.nextToken());
q.add(new Pair(--x,--y));
}
bfs();
String ans = "" + (result.x+1) +" "+ (result.y+1);
out.write(ans);
}catch(IOException e){
}
}
static void bfs(){
while(!q.isEmpty()){
Pair temp = q.poll();
if(visited[temp.x][temp.y]) continue;
visited[temp.x][temp.y] = true;
result.x = temp.x;
result.y= temp.y;
for(int i=0;i<4;i++){
int x = temp.x + dx[i];
int y = temp.y + dy[i];
if(x>=0 && x<n && y>=0 && y<m && !visited[x][y])
q.add(new Pair(x,y));
}
}
}
}
class Pair{
int x,y;
public Pair(int x,int y){
this.x=x;
this.y=y;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.awt.Point;
import java.util.LinkedList;
import java.util.Queue;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
Scanner scan = new Scanner("input.txt");
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
int n,m;
n = scan.nextInt();
m = scan.nextInt();
boolean visited[][] = new boolean[n][m];
int numOfStartingPoints;
numOfStartingPoints = scan.nextInt();
int resX = 0, resY = 0;
Queue<Point> que = new LinkedList<Point>();
for (int i = 0; i < numOfStartingPoints; i++) {
int x = scan.nextInt() - 1;
int y = scan.nextInt() - 1;
que.add(new Point(x, y));
visited[x][y] = true;
}
while (true) {
Point current = que.poll();
if (current == null) {
break;
} else {
resX = current.x;
resY = current.y;
if (current.x + 1 < n && !visited[current.x + 1][current.y])
{
que.add(new Point(current.x + 1, current.y));
visited[current.x + 1][current.y] = true;
}
if (current.y + 1 < m && !visited[current.x][current.y + 1])
{
que.add(new Point(current.x, current.y + 1));
visited[current.x][current.y + 1] = true;
}
if (current.x - 1 >= 0 && !visited[current.x - 1][current.y])
{
que.add(new Point(current.x - 1, current.y));
visited[current.x - 1][current.y] = true;
}
if (current.y - 1 >= 0 && !visited[current.x][current.y - 1])
{
que.add(new Point(current.x, current.y - 1));
visited[current.x][current.y - 1] = true;
}
}
}
out.printf("%d %d\n", ++resX, ++resY);
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(String s) throws FileNotFoundException{ br = new BufferedReader(new FileReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class P35C {
final static int SHIFT = 11;
final static int MASK = (1 << SHIFT) - 1;
final static int [] DX = {-1, 1, 0, 0};
final static int [] DY = { 0, 0, -1, 1};
public void run() throws Exception {
int m = nextInt();
int n = nextInt();
boolean [][] burned = new boolean [n][m];
List<Integer> burn = new ArrayList();
for (int k = nextInt(); k > 0; k--) {
int x = nextInt() - 1;
int y = nextInt() - 1;
burned[y][x] = true;
burn.add((x << SHIFT) | y);
}
int lastXY = 0;
List<Integer> newBurn = null;
do {
lastXY = burn.get(0);
newBurn = new ArrayList();
for (int xy : burn) {
int x = xy >> SHIFT;
int y = xy & MASK;
for (int i = 0; i < 4; i++) {
int nx = x + DX[i];
int ny = y + DY[i];
if ((ny >= 0) && (ny < n) && (nx >= 0) && (nx < m) && (!burned[ny][nx])) {
burned[ny][nx] = true;
newBurn.add((nx << SHIFT) | ny);
}
}
}
burn = newBurn;
} while (newBurn.size() > 0);
println(((lastXY >> SHIFT) + 1) + " " + ((lastXY & MASK) + 1));
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt")));
new P35C().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
import java.awt.Point;
public class Main{
public static void main(String[] args)throws FileNotFoundException,IOException{
File file = new File("input.txt");
Scanner sc = new Scanner(file);
File outFile = new File("output.txt");
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
int w = sc.nextInt();
int h = sc.nextInt();
boolean[][] map = new boolean[h+1][w+1]; //false:�u�G�v���ĂȂ�
int x = -1, y = -1;
Queue<Point> open = new LinkedList<Point>();
int k = sc.nextInt();
for(int i=0;i<k;i++){
int tx = sc.nextInt();
int ty = sc.nextInt();
map[ty][tx] = true;
x = tx;
y = ty;
open.add(new Point(x,y));
}
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
while(!open.isEmpty()){
Point p = open.poll();
for(int i=0;i<4;i++){
int nx = p.x + dx[i];
int ny = p.y + dy[i];
if(nx>0 && nx<=w && ny>0 && ny<=h && !map[ny][nx]){
map[ny][nx] = true;
x = nx;
y = ny;
open.add(new Point(nx,ny));
}
}
}
pw.println(x + " " + y);
pw.close();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
@SuppressWarnings("unchecked")
public class P35C {
final static int [] DX = {-1, 1, 0, 0};
final static int [] DY = { 0, 0, -1, 1};
public void run() throws Exception {
int m = nextInt();
int n = nextInt();
boolean [][] burned = new boolean [n][m];
List<Integer> burn = new ArrayList();
for (int k = nextInt(); k > 0; k--) {
int x = nextInt() - 1;
int y = nextInt() - 1;
burned[y][x] = true;
burn.add(x * 10000 + y);
}
int lastXY = 0;
List<Integer> newBurn = null;
do {
lastXY = burn.get(0);
newBurn = new ArrayList();
for (int xy : burn) {
int x = xy / 10000;
int y = xy % 10000;
for (int i = 0; i < 4; i++) {
int nx = x + DX[i];
int ny = y + DY[i];
if ((ny >= 0) && (ny < n) && (nx >= 0) && (nx < m) && (!burned[ny][nx])) {
burned[ny][nx] = true;
newBurn.add(nx * 10000 + ny);
}
}
}
burn = newBurn;
} while (newBurn.size() > 0);
println((lastXY / 10000 + 1) + " " + (lastXY % 10000 + 1));
}
public static void main(String... args) throws Exception {
br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream("output.txt")));
new P35C().run();
br.close();
pw.close();
System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
}
static long startTime = System.currentTimeMillis();
static BufferedReader br;
static PrintWriter pw;
StringTokenizer stok;
String nextToken() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = br.readLine();
if (s == null) { return null; }
stok = new StringTokenizer(s);
}
return stok.nextToken();
}
void print(byte b) { print("" + b); }
void print(int i) { print("" + i); }
void print(long l) { print("" + l); }
void print(double d) { print("" + d); }
void print(char c) { print("" + c); }
void print(Object o) {
if (o instanceof int[]) { print(Arrays.toString((int [])o));
} else if (o instanceof long[]) { print(Arrays.toString((long [])o));
} else if (o instanceof char[]) { print(Arrays.toString((char [])o));
} else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
} else if (o instanceof short[]) { print(Arrays.toString((short [])o));
} else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
} else if (o instanceof float[]) { print(Arrays.toString((float [])o));
} else if (o instanceof double[]) { print(Arrays.toString((double [])o));
} else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
} else { print("" + o); }
}
void print(String s) { pw.print(s); }
void println() { println(""); }
void println(byte b) { println("" + b); }
void println(int i) { println("" + i); }
void println(long l) { println("" + l); }
void println(double d) { println("" + d); }
void println(char c) { println("" + c); }
void println(Object o) { print(o); println(); }
void println(String s) { pw.println(s); }
int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
long nextLong() throws IOException { return Long.parseLong(nextToken()); }
double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
char nextChar() throws IOException { return (char) (br.read()); }
String next() throws IOException { return nextToken(); }
String nextLine() throws IOException { return br.readLine(); }
int [] readInt(int size) throws IOException {
int [] array = new int [size];
for (int i = 0; i < size; i++) { array[i] = nextInt(); }
return array;
}
long [] readLong(int size) throws IOException {
long [] array = new long [size];
for (int i = 0; i < size; i++) { array[i] = nextLong(); }
return array;
}
double [] readDouble(int size) throws IOException {
double [] array = new double [size];
for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
return array;
}
String [] readLines(int size) throws IOException {
String [] array = new String [size];
for (int i = 0; i < size; i++) { array[i] = nextLine(); }
return array;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.awt.Point;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class FireAgain {
Point coordinate;
Queue<Point> q = new LinkedList<Point>();
int m, n;
boolean[][] arr;
PrintStream out ;
void bfs(Point start) {
while (!q.isEmpty()) {
Point front = q.poll();
Point p = new Point();
p.x = front.x - 1;
p.y = front.y;
if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1) {
if (!arr[p.x][p.y]) {
arr[p.x][p.y] = true;
q.add(p);
}
}
p = new Point();
p.x = front.x + 1;
p.y = front.y;
if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)
if (!arr[p.x][p.y]) {
arr[p.x][p.y] = true;
q.add(p);
}
p = new Point() ;
p.x = front.x;
p.y = front.y + 1;
if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)
if (!arr[p.x][p.y]) {
arr[p.x][p.y] = true;
q.add(p);
}
p = new Point() ;
p.x = front.x;
p.y = front.y - 1;
if (p.x >= 1 && p.x <= n && p.y <= m && p.y >= 1)
if (!arr[p.x][p.y]) {
arr[p.x][p.y] = true;
q.add(p);
}
if (q.size() == 0)
out.print(front.x + " " + front.y);
}
}
/**
* @param args
* @throws FileNotFoundException
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
FireAgain fa = new FireAgain();
Scanner Scan = new Scanner(new FileInputStream("input.txt"));
fa.out = new PrintStream(new File("output.txt"));
fa.n = Scan.nextInt();
fa.m = Scan.nextInt();
int k = Scan.nextInt();
fa.arr = new boolean[2001][2001];
for (int i = 0; i < k; i++) {
fa.coordinate = new Point();
fa.coordinate.x = Scan.nextInt();
fa.coordinate.y = Scan.nextInt();
fa.q.add(fa.coordinate);
fa.arr[fa.coordinate.x][fa.coordinate.y] = true;
}
fa.bfs(fa.q.peek());
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
public class C {
public static void main(String[] args) throws Exception {
final int fuck = 2001;
Scanner in = new Scanner(new File("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = in.nextInt(), m = in.nextInt();
int[] D = new int[ fuck*fuck ],
dx = new int[] { 1, -1, 0, 0},
dy = new int[] { 0, 0, -1, 1};
Arrays.fill(D, -1);
ArrayDeque<Integer> Q = new ArrayDeque<>();
int k = in.nextInt(), ans = 0;
for(int i = 0; i < k; ++i) {
int x = in.nextInt(), y = in.nextInt();
D[ans = (x * fuck + y)] = 0;
Q.offer(ans);
}
while(!Q.isEmpty()) {
int idx = Q.poll();
int x = idx / fuck, y = idx % fuck;
for(int i = 0; i < 4; ++i) {
int wtf = (dx[i] + x) * fuck + (dy[i] + y);
if(dx[i] + x <= n && dx[i] + x >= 1 && dy[i] + y <= m && dy[i] + y >= 1 && D[wtf] == -1) {
D[wtf] = D[idx] + 1;
Q.offer(wtf);
if(D[wtf] >= D[ans])
ans = wtf;
}
}
}
out.println((ans / fuck) + " " + (ans % fuck));
out.close();
in.close();
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
Scanner read = new Scanner(new FileInputStream(new File("input.txt")));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = read.nextInt(), m = read.nextInt(), k = read.nextInt(), tree[][] = new int[n][m], a[] = new int[k],
b[] = new int[k], x = 0, y = 0, max = -1, d = 0;
for (int i = 0; i < k; i++) {
a[i] = read.nextInt() - 1;
b[i] = read.nextInt() - 1;
tree[a[i]][b[i]] = 0;
}
for(int i = 0; i < n; i++){
Arrays.fill(tree[i], Integer.MAX_VALUE);
}
for (int o = 0; o < k; o++) {
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
d = Math.abs(a[o] - i) + Math.abs(b[o] - j);
if(d < tree[i][j])
tree[i][j] = d;
}
}
}
for(int i = 0; i<n; i++){
for(int j = 0; j < m ; j ++){
if(tree[i][j] > max){
max= tree[i][j];
x= i;
y = j;
}
}
}
out.println(x + 1 + " " + (y + 1));
out.close();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
@SuppressWarnings("unused")
public class Fire35C {
InputStream is;
PrintWriter out;
String INPUT = "";
int mod = (int)(Math.pow(10,9)+7);
int v = 0;
int max = 0;
StringBuilder st = new StringBuilder();
File outFile = new File("output.txt");
void solve() throws IOException
{
int n = ni();
int m = ni();
boolean visited[][] = new boolean[n][m];
boolean inq[][] = new boolean[n][m];
Queue<Integer> x = new LinkedList<>();
Queue<Integer> y = new LinkedList<>();
Queue<Integer> lev = new LinkedList<>();
int a = -1 , b = -1 , max = 0;
int k = ni();
while(k-- > 0) {
int u = ni()-1;
int v = ni()-1;
x.add(u);
y.add(v);
lev.add(1);
inq[u][v] = true;
}
while(x.size() != 0) {
int u = x.poll();
int v = y.poll();
int l = lev.poll();
if(max < l) {
a = u;
b = v;
max = l;
}
visited[u][v] = true;
if(u-1 >= 0 && !visited[u-1][v] && !inq[u-1][v]) {
x.add(u-1);
y.add(v);
lev.add(l+1);
inq[u-1][v] = true;
}
if(u+1 < n && !visited[u+1][v] && !inq[u+1][v]) {
x.add(u+1);
y.add(v);
lev.add(l+1);
inq[u+1][v] = true;
}
if(v-1 >= 0 && !visited[u][v-1] && !inq[u][v-1]) {
x.add(u);
y.add(v-1);
lev.add(l+1);
inq[u][v-1] = true;
}
if(v+1 < m && !visited[u][v+1] && !inq[u][v+1]) {
x.add(u);
y.add(v+1);
lev.add(l+1);
inq[u][v+1] = true;
}
}
a++;
b++;
out.println(a+" "+b);
out.close();
}
void run() throws Exception
{
is = INPUT.isEmpty() ? new FileInputStream(new File("input.txt")) : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(new BufferedWriter(new FileWriter(outFile)));
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Fire35C().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b) && b != ' ')){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int[][] na(int n , int m)
{
int[][] a = new int[n][m];
for(int i = 0;i < n;i++)
for(int j = 0 ; j<m ; j++) a[i][j] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
void display2D(int a[][]) {
for(int i[] : a) {
for(int j : i) {
out.print(j+" ");
}
out.println();
}
}
int[][] creategraph(int n , int m) {
int g[][] = new int[n+1][];
int from[] = new int[m];
int to[] = new int[m];
int ct[] = new int[n+1];
for(int i = 0 ; i<m; i++) {
from[i] = ni();
to[i] = ni();
ct[from[i]]++;
ct[to[i]]++;
}
int parent[] = new int[n+1];
for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];
for(int i = 0 ; i<m ; i++) {
g[from[i]][--ct[from[i]]] = to[i];
g[to[i]][--ct[to[i]]] = from[i];
}
return g;
}
static long __gcd(long a, long b)
{
if(b == 0)
{
return a;
}
else
{
return __gcd(b, a % b);
}
}
// To compute x^y under modulo m
static long power(long x, long y, long p)
{
// Initialize result
long res = 1;
// Update x if it is more than or
// equal to p
x = x % p;
while (y > 0)
{
// If y is odd, multiply x
// with result
if (y % 2 == 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Function to find modular
// inverse of a under modulo m
// Assumption: m is prime
static long modInverse(long a, int m)
{
if (__gcd(a, m) != 1) {
//System.out.print("Inverse doesn't exist");
return -1;
}
else {
// If a and m are relatively prime, then
// modulo inverse is a^(m-2) mode m
// System.out.println("Modular multiplicative inverse is "
// +power(a, m - 2, m));
return power(a, m - 2, m);
}
}
static long nCrModPFermat(int n, int r,
int p , long fac[])
{
// Base case
if (r == 0)
return 1;
// Fill factorial array so that we
// can find all factorial of r, n
// and n-r
long t = (fac[n]* modInverse(fac[r], p))%p;
return ( (t* modInverse(fac[n-r], p))% p);
}
private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author zodiacLeo
*/
public class Main
{
public static void main(String[] args)
{
InputStream inputStream;
try
{
inputStream = new FileInputStream("input.txt");
} catch (IOException e)
{
throw new RuntimeException(e);
}
OutputStream outputStream;
try
{
outputStream = new FileOutputStream("output.txt");
} catch (IOException e)
{
throw new RuntimeException(e);
}
FastScanner in = new FastScanner(inputStream);
FastPrinter out = new FastPrinter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
private final static int[] dx = {-1, 0, +1, 0};
private final static int[] dy = {0, +1, 0, -1};
private final static int WHITE = 123456789;
public void solve(int testNumber, FastScanner in, FastPrinter out)
{
int n = in.nextInt();
int m = in.nextInt();
int[][] map = new int[n][m];
for (int i = 0; i < n; i++)
{
Arrays.fill(map[i], WHITE);
}
int k = in.nextInt();
int qh = 0;
int qt = 0;
int[] q = new int[((int) 7e6)];
for (int i = 0; i < k; i++)
{
int x = in.nextInt() - 1;
int y = in.nextInt() - 1;
map[x][y] = 0;
q[qh++] = x * m + y;
}
int d = 0;
int X = q[0] / m;
int Y = q[0] % m;
while (qt < qh)
{
int pos = q[qt++];
int x = pos / m;
int y = pos % m;
for (int i = 0; i < 4; i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if (isValid(xx, n) && isValid(yy, m) && map[xx][yy] == WHITE)
{
map[xx][yy] = map[x][y] + 1;
q[qh++] = (xx * m) + yy;
if (d < map[xx][yy])
{
d = map[xx][yy];
X = xx;
Y = yy;
}
}
}
}
// for (int i = 0; i < n; i++)
// {
// for (int j = 0; j < m; j++)
// {
// out.print(map[i][j] + " ");
// }
// out.println();
// }
out.println((X + 1) + " " + (Y + 1));
}
private boolean isValid(int x, int X)
{
return x >= 0 && x < X;
}
}
static class FastScanner
{
public BufferedReader br;
public StringTokenizer st;
public FastScanner(InputStream is)
{
br = new BufferedReader(new InputStreamReader(is));
}
public FastScanner(File f)
{
try
{
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
public String next()
{
while (st == null || !st.hasMoreElements())
{
String s = null;
try
{
s = br.readLine();
} catch (IOException e)
{
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
}
static class FastPrinter extends PrintWriter
{
public FastPrinter(OutputStream out)
{
super(out);
}
public FastPrinter(Writer out)
{
super(out);
}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class Main {
static boolean used[][];
static int n;
static int m;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter("output.txt");
n = nextInt();
m = nextInt();
int k = nextInt();
used = new boolean[n][m];
Deque<point> deq = new ArrayDeque<>();
for (int i = 0; i < k; i++) {
deq.addLast(new point(nextInt() - 1, nextInt() - 1));
used[deq.peekLast().x][deq.peekLast().y] = true;
}
point last = new point(0, 0);
while (!deq.isEmpty()) {
point v = deq.pollFirst();
int x = v.x;
int y = v.y;
if (checker(x, y + 1)) {
last = new point(x, y + 1);
deq.addLast(new point(x, y + 1));
used[x][y + 1] = true;
}
if (checker(x, y - 1)) {
last = new point(x, y - 1);
deq.addLast(new point(x, y - 1));
used[x][y - 1] = true;
}
if (checker(x + 1, y)) {
last = new point(x + 1, y);
deq.addLast(new point(x + 1, y));
used[x + 1][y] = true;
}
if (checker(x - 1, y)) {
last = new point(x - 1, y);
deq.addLast(new point(x - 1, y));
used[x - 1][y] = true;
}
}
out.println(last.x + 1 + " " + (last.y + 1));
out.close();
}
static boolean checker(int x, int y) {
if (x < n && y < m && x >= 0 && y >= 0 && !used[x][y]) return true;
return false;
}
static StringTokenizer st = new StringTokenizer("");
static BufferedReader br;
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
}
class point {
int x, y;
public point(int x, int y) {
this.x = x;
this.y = y;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader//(new InputStreamReader(System.in));
(new FileReader("input.txt"));
StringBuilder out = new StringBuilder();
StringTokenizer tk;
PrintWriter pw = new PrintWriter("output.txt", "UTF-8");
int [] dx = {-1,1,0,0},dy = {0,0,-1,1};
tk = new StringTokenizer(in.readLine());
int n = parseInt(tk.nextToken()),m = parseInt(tk.nextToken());
int k = parseInt(in.readLine());
int [][] dist = new int[n][m];
for(int i=0; i<n; i++)
Arrays.fill(dist[i], -1);
int ans = -1,atx = -1,aty = -1;
Queue<point> q = new LinkedList<point>();
tk = new StringTokenizer(in.readLine());
while(k-- > 0) {
int x = parseInt(tk.nextToken())-1,y = parseInt(tk.nextToken())-1;
dist[x][y] = 0;
q.add(new point(x,y));
}
while(!q.isEmpty()) {
point p = q.remove();
if(dist[p.x][p.y]>ans) {
ans = dist[p.x][p.y];
atx = p.x+1;
aty = p.y+1;
}
for(int i=0; i<4; i++) {
int nx = p.x + dx[i];
int ny = p.y + dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m && dist[nx][ny]==-1) {
dist[nx][ny] = dist[p.x][p.y] + 1;
q.add(new point(nx,ny));
}
}
}
pw.println(atx+" "+aty);
pw.close();
}
}
class point {
int x,y;
public point(int x,int y) {
this.x = x;
this.y = y;
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class practice {
public static void main(String[] args) throws FileNotFoundException {
Scanner scn = new Scanner(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n=scn.nextInt(),m=scn.nextInt(),k=scn.nextInt();
int[][] inf=new int[k][2];
for(int i=0;i<k;i++){
inf[i][0]=scn.nextInt();inf[i][1]=scn.nextInt();
}
int ans=0,x=1,y=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int temp=Integer.MAX_VALUE;
for(int l=0;l<k;l++){
temp=Math.min(temp, Math.abs(i-inf[l][0])+Math.abs(j-inf[l][1]));
}
if(temp>ans){
ans=temp;x=i;y=j;
}
}
}
out.print(x+ " " + y);
out.close();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
Scanner read = new Scanner(new FileInputStream(new File("input.txt")));
PrintWriter out = new PrintWriter(new File("output.txt"));
int n = read.nextInt(), m = read.nextInt(), k = read.nextInt(), tree[][] = new int[n][m], a[] = new int[k],
b[] = new int[k], x = 0, y = 0, max = -1, d = 0;
for (int i = 0; i < k; i++) {
a[i] = read.nextInt() - 1;
b[i] = read.nextInt() - 1;
tree[a[i]][b[i]] = 0;
}
for(int i = 0; i < n; i++){
Arrays.fill(tree[i], Integer.MAX_VALUE);
}
for (int o = 0; o < k; o++) {
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
d = Math.abs(a[o] - i) + Math.abs(b[o] - j);
if(d < tree[i][j])
tree[i][j] = d;
}
}
}
for(int i = 0; i<n; i++){
for(int j = 0; j < m ; j ++){
if(tree[i][j] > max){
max= tree[i][j];
x= i;
y = j;
}
}
}
out.println(x + 1 + " " + (y + 1));
out.close();
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args) throws IOException
{
PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
Scanner in=new Scanner(new File("input.txt"));
int n,m,k;
n=in.nextInt();
m=in.nextInt();
k=in.nextInt();
Vector<Integer> vec=new Vector<Integer>();
Vector<Integer> temp=new Vector<Integer>();
boolean[][] mas=new boolean[n][m];
long time=System.currentTimeMillis();
for(int i=0;i<k;i++)
{
vec.add(in.nextInt()-1);
vec.add(in.nextInt()-1);
mas[vec.get(vec.size()-2)][vec.get(vec.size()-1)]=true;
}
int x,y;
x=y=0;
while(vec.size()!=0)
{
for(int i=0;i<vec.size();i+=2)
{
x=vec.get(i);
y=vec.get(i+1);
if(x>0 && !mas[x-1][y])
{
temp.add(x-1);
temp.add(y);
mas[x-1][y]=true;
}
if(x<n-1 && !mas[x+1][y])
{
temp.add(x+1);
temp.add(y);
mas[x+1][y]=true;
}
if(y>0 && !mas[x][y-1])
{
temp.add(x);
temp.add(y-1);
mas[x][y-1]=true;
}
if(y<m-1 && !mas[x][y+1])
{
temp.add(x);
temp.add(y+1);
mas[x][y+1]=true;
}
}
vec=temp;
temp=new Vector<Integer>();
}
pw.println((x+1)+" "+(y+1));
System.out.println(System.currentTimeMillis()-time);
in.close();
pw.close();
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.Queue;
public class A {
static int[] dx = {-1, 0, 1, 0};
static int[] dy = {0, 1, 0, -1};
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner("input.txt");
PrintWriter out = new PrintWriter("output.txt");
int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
int[][] dist = new int[n][m];
for(int[] a : dist) Arrays.fill(a, -1);
Queue<Point> q = new LinkedList<>();
for(int i = 0; i < k; i++)
{
int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
dist[x][y] = 0;
q.add(new Point(x, y));
}
int ansX = -1, ansY = -1;
while(!q.isEmpty())
{
Point cur = q.remove();
ansX = cur.x; ansY = cur.y;
for(int i = 0; i < 4; i++)
{
int x = cur.x + dx[i], y = cur.y + dy[i];
if(x != -1 && y != -1 && x != n && y != m && dist[x][y] == -1)
{
q.add(new Point(x, y));
dist[x][y] = dist[cur.x][cur.y] + 1;
}
}
}
out.println((ansX + 1) + " " + (ansY + 1));
out.flush();
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream system) {br = new BufferedReader(new InputStreamReader(system));}
public Scanner(String file) throws Exception {br = new BufferedReader(new FileReader(file));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String nextLine()throws IOException{return br.readLine();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public double nextDouble() throws IOException {return Double.parseDouble(next());}
public char nextChar()throws IOException{return next().charAt(0);}
public Long nextLong()throws IOException{return Long.parseLong(next());}
public boolean ready() throws IOException{return br.ready();}
public void waitForInput() throws InterruptedException {Thread.sleep(4000);}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeSet;
public class ViewAngle{
private static int V,level[][],count=-1,lev_dfs[],degree=0,no_vert_conn_comp=0;
private static Stack <Integer>st=new Stack();
private static LinkedList<Integer > adj[];
private static boolean[][] Visite;
private static boolean [] Visited;
private static TreeSet<Integer> ts=new TreeSet();
// private static HashMap
private static Queue<Pair> queue = new LinkedList<Pair>();
ViewAngle(int V){
V++;
this.V=(V);
adj=new LinkedList[V];
Visite=new boolean[100][100];
Visited=new boolean[V];
lev_dfs=new int[V];
for(int i=0;i<V;i++)
adj[i]=new LinkedList<Integer>();
}
static File inFile,outFile;
static FileWriter fWriter;
static PrintWriter pWriter;
public static void main(String[] args) throws IOException {
inFile=new File("input.txt");
outFile = new File ("output.txt");
fWriter = new FileWriter (outFile);
pWriter = new PrintWriter (fWriter);
Scanner sc = new Scanner (inFile);
int n=sc.nextInt();
int m=sc.nextInt();
char c[][]=new char[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
c[i][j]='.';
}
}
setup(n, m);
int k=sc.nextInt();
for(int i=0;i<k;i++){
int x=sc.nextInt();
int y=sc.nextInt();
queue.add(new Pair(x-1, y-1));
c[x-1][y-1]='X';
level[x-1][y-1]=-1;
Visite[x-1][y-1]=true;
}
BFS(c, n, m);
pWriter.close();
sc.close();
}
static void addEdge(int v,int w){
if(adj[v]==null){
adj[v]=new LinkedList();
}
adj[v].add(w);
}
public static int BFS2(int startVert,int dest){
Visited=new boolean[V];
for(int i=1;i<V;i++){
lev_dfs[i]=-1;
}
Queue<Integer> q=new LinkedList<Integer>();
q.add(startVert);
lev_dfs[startVert]=0;
while(!q.isEmpty()){
int top=q.poll();
Iterator<Integer> i= adj[top].listIterator();
while(i.hasNext()){
int n=i.next();
if(!Visited[n]){
q.add(n);
Visited[n]=true;
lev_dfs[n]=lev_dfs[top]+1;
if(n==dest){
q.clear();
return lev_dfs[n];
}
}
}
}
q.clear();
return -1;
}
public int getEd(){
return degree/2;
}
public void get(int from,int to){
int h=lev_dfs[from]-lev_dfs[to];
if(h<=0){
System.out.println(-1);
}else{
System.out.println(h-1);
}
}
public static void setup(int n,int m){
level=new int[n][m];
Visite=new boolean[n][m];
}
private static boolean check(int x,int y,char c[][]){
if((x>=0 && y>=0) && (x<c.length && y<c[0].length) && c[x][y]=='.'){
return true;
}
return false;
}
public static int BFS(char[][] c,int n,int m)
{
//Visited[s]=true;
// queue.add(new Pair(x,y));
int count=0;
// level[x][y]=-1;
while (!queue.isEmpty())
{
Pair temp = queue.poll();
int x=temp.w;
int y=temp.h;
Visite[x][y]=true;
if(check(x+1,y,c) && !Visite[x+1][y]){
level[x+1][y]=level[x][y]+1;
queue.add(new Pair(x+1, y));
Visite[x+1][y]=true;
}
if(check(x-1,y,c) && !Visite[x-1][y]){
level[x-1][y]=level[x][y]+1;
queue.add(new Pair(x-1, y));
Visite[x-1][y]=true;
}
if(check(x,y+1,c) && !Visite[x][y+1]){
level[x][y+1]=level[x][y]+1;
queue.add(new Pair(x, y+1));
Visite[x][y+1]=true;
}
if(check(x,y-1,c) && !Visite[x][y-1]){
level[x][y-1]=level[x][y]+1;
queue.add(new Pair(x, y-1));
Visite[x][y-1]=true;
}
}
int prev_lev=-1,x=-1,y=-1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(level[i][j]>=prev_lev){
prev_lev=level[i][j];
x=i;y=j;
}
//System.out.println(level[i][j]+" ");
}
//System.out.println();
}
pWriter.println((x+1)+" "+(y+1));
return V;
}
private void getAns(int startVertex){
for(int i=0;i<adj[startVertex].size();i++){
int ch=adj[startVertex].get(i);
for(int j=0;j<adj[ch].size();j++){
int ch2=adj[ch].get(j);
if(adj[ch2].contains(startVertex)){
System.out.println(startVertex+" "+ch+" "+ch2);
System.exit(0);
}
}
}
}
public long dfs(int startVertex){
// getAns(startVertex);
if(!Visited[startVertex]) {
return dfsUtil(startVertex,Visited);
//return getAns();
}
return 0;
}
private long dfsUtil(int startVertex, boolean[] Visited) {//0-Blue 1-Pink
//System.out.println(startVertex);
int c=1;
long cout=0;
degree=0;
Visited[startVertex]=true;
// lev_dfs[startVertex]=1;
st.push(startVertex);
while(!st.isEmpty()){
int top=st.pop();
Iterator<Integer> i=adj[top].listIterator();
degree+=adj[top].size();
while(i.hasNext()){
// System.out.println(top+" "+adj[top].size());
int n=i.next();
// System.out.print(n+" ");
if( !Visited[n]){
Visited[n]=true;
st.push(n);
// System.out.print(n+" ");
lev_dfs[n]=top;
}
}
// System.out.println("--------------------------------");
}
for(int i=1;i<V;i++){
if(lev_dfs[i]!=0){
System.out.print(lev_dfs[i]+" ");
}
}
return cout;
// System.out.println("NO");
// return c;
}
}
class Pair implements Comparable<Pair>{
int w;
int h;
Pair(int w,int h){
this.w=w;
this.h=h;
}
@Override
public int compareTo(Pair o) {
// TODO Auto-generated method stub
// Sort in increasing order
if(w>o.w){
return 1;
}else if(w<o.w){
return -1;
}else{
if(h>o.h)
return 1;
else if(h<o.h)
return -1;
else
return 0;
}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
//InputStream input = System.in;
//OutputStream output = System.out;
InputReader in = new InputReader(new FileReader(new File("input.txt")));
PrintWriter out = new PrintWriter(new FileWriter(new File("output.txt")));
//InputReader in = new InputReader(input);
//PrintWriter out = new PrintWriter(output);
Solution s = new Solution();
s.solve(1, in, out);
out.close();
}
static class Solution {
double EPS = 0.0000001;
public void solve(int cs, InputReader in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt();
Graph g = new Graph(n, m);
int k = in.nextInt();
for (int[] v : g.vis)
Arrays.fill(v, -1);
while (k-- > 0) {
Pair start = new Pair(in.nextInt()-1, in.nextInt()-1);
g.bfs(start);
}
int idx1 = 0, idx2 = 0, max = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; ++j) {
if (g.vis[i][j] > max) {
idx1 = i;
idx2 = j;
max = g.vis[i][j];
}
}
}
out.println((idx1+1) + " " + (idx2+1));
}
static class Pair {
int x, y;
public Pair(int x, int y) {
this.x = x ;
this.y = y;
}
}
static class Graph {
LinkedList<Integer> adj[];
int n, e;
int[][] vis;
@SuppressWarnings("unchecked")
public Graph(int n, int e) {
this.n = n;
this.e = e;
adj = new LinkedList[n];
for (int i = 0; i < n; ++i)
adj[i] = new LinkedList<>();
vis = new int[n][e];
}
int[] dx = {0, 0, 1, -1};
int[] dy = {1, -1, 0, 0};
void bfs(Pair src) {
Queue<Pair> q = new LinkedList<>();
vis[src.x][src.y] = 0;
q.add(src);
while (!q.isEmpty()) {
Pair p = q.poll();
for (int k = 0; k < 4; k++) {
int ni = p.x+dx[k];
int nj = p.y+dy[k];
if (isValid(ni, nj) && (vis[ni][nj] == -1 || vis[p.x][p.y]+1 < vis[ni][nj])) {
vis[ni][nj] = vis[p.x][p.y]+1;
q.add(new Pair(ni, nj));
}
}
}
}
boolean isValid(int i, int j) {
return i >= 0 && i < n && j >= 0 && j < e;
}
}
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream i) {
br = new BufferedReader(new InputStreamReader(i), 32768);
st = null;
}
public InputReader(FileReader s) {
br = new BufferedReader(s);
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader(){
din=new DataInputStream(System.in);
buffer=new byte[BUFFER_SIZE];
bufferPointer=bytesRead=0;
}
public Reader(String file_name) throws IOException{
din=new DataInputStream(new FileInputStream(file_name));
buffer=new byte[BUFFER_SIZE];
bufferPointer=bytesRead=0;
}
public String readLine() throws IOException{
byte[] buf=new byte[64]; // line length
int cnt=0,c;
while((c=read())!=-1){
if(c=='\n')break;
buf[cnt++]=(byte)c;
}
return new String(buf,0,cnt);
}
public int nextInt() throws IOException{
int ret=0;byte c=read();
while(c<=' ')c=read();
boolean neg=(c=='-');
if(neg)c=read();
do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');
if(neg)return -ret;
return ret;
}
public long nextLong() throws IOException{
long ret=0;byte c=read();
while(c<=' ')c=read();
boolean neg=(c=='-');
if(neg)c=read();
do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');
if(neg)return -ret;
return ret;
}
public double nextDouble() throws IOException{
double ret=0,div=1;byte c=read();
while(c<=' ')c=read();
boolean neg=(c=='-');
if(neg)c = read();
do {ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');
if(c=='.')while((c=read())>='0'&&c<='9')
ret+=(c-'0')/(div*=10);
if(neg)return -ret;
return ret;
}
private void fillBuffer() throws IOException{
bytesRead=din.read(buffer,bufferPointer=0,BUFFER_SIZE);
if(bytesRead==-1)buffer[0]=-1;
}
private byte read() throws IOException{
if(bufferPointer==bytesRead)fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException{
if(din==null) return;
din.close();
}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class A {
static final int[] dx = {0, 0, -1, 1};
static final int[] dy = {-1, 1, 0, 0};
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner("input.txt");
PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
// Scanner sc = new Scanner(System.in);
// PrintWriter out = new PrintWriter(System.out);
int N = sc.nextInt(), M = sc.nextInt();
int[][] dist = new int[N][M];
Queue<Integer> q = new LinkedList<>();
int K = sc.nextInt();
while(K-->0)
{
int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
q.add(x * M + y);
dist[x][y] = 1;
}
int max = 0, ansX = -1, ansY = -1;
while(!q.isEmpty())
{
int u = q.remove(), x = u / M, y = u % M;
if(dist[x][y] > max)
max = dist[ansX = x][ansY = y];
for(int k = 0; k < 4; ++k)
{
int nx = x + dx[k], ny = y + dy[k];
if(nx >= 0 && ny >= 0 && nx < N && ny < M && dist[nx][ny] == 0)
{
dist[nx][ny] = dist[x][y] + 1;
q.add(nx * M + ny);
}
}
}
out.printf("%d %d\n", ansX + 1, ansY + 1);
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public Scanner(String s) throws FileNotFoundException{ br = new BufferedReader(new FileReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException { return Double.parseDouble(next()); }
public boolean ready() throws IOException {return br.ready();}
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class P35C {
public static void main(String[] args) throws FileNotFoundException {
InputStream inputStream = new FileInputStream("input.txt");
OutputStream outputStream = new FileOutputStream("output.txt");
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(in, out);
out.close();
}
static class Task {
private class Point {
int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
private int dis(int i, int j, Point p2) {
return Math.abs(i - p2.x) + Math.abs(j - p2.y);
}
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt(), m = in.nextInt();
int k = in.nextInt();
Point[] ps = new Point[k];
for (int i = 0; i < k; i++) {
ps[i] = new Point(in.nextInt() - 1, in.nextInt() - 1);
}
int max = 0;
Point argmax = ps[0];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int val = dis(i, j, ps[0]);
for (int l = 1; l < k; l++) {
val = Math.min(val, dis(i, j, ps[l]));
}
if (val > max) {
max = val;
argmax = new Point(i, j);
}
}
}
out.println((argmax.x + 1) + " " + (argmax.y + 1));
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class x35C
{
public static void main(String hi[]) throws Exception
{
BufferedReader infile = new BufferedReader(new FileReader("input.txt"));
StringTokenizer st = new StringTokenizer(infile.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int K = Integer.parseInt(infile.readLine());
int[][] grid = new int[N][M];
for(int i=0; i < N; i++)
Arrays.fill(grid[i], -1);
ArrayDeque<Integer> q = new ArrayDeque<Integer>();
st = new StringTokenizer(infile.readLine());
while(K-->0)
{
int a = Integer.parseInt(st.nextToken())-1;
int b = Integer.parseInt(st.nextToken())-1;
grid[a][b] = 0;
q.add(a); q.add(b);
}
while(q.size() > 0)
{
int x = q.poll();
int y = q.poll();
if(x > 0 && grid[x-1][y] == -1)
{
grid[x-1][y] = grid[x][y]+1;
q.add(x-1); q.add(y);
}
if(y > 0 && grid[x][y-1] == -1)
{
grid[x][y-1] = grid[x][y]+1;
q.add(x); q.add(y-1);
}
if(x+1 < N && grid[x+1][y] == -1)
{
grid[x+1][y] = grid[x][y]+1;
q.add(x+1); q.add(y);
}
if(y+1 < M && grid[x][y+1] == -1)
{
grid[x][y+1] = grid[x][y]+1;
q.add(x); q.add(y+1);
}
}
int r = 0;
int c = 0;
for(int i=0; i < N; i++)
for(int j=0; j < M; j++)
if(grid[r][c] < grid[i][j])
{
r = i;
c = j;
}
r++; c++;
System.setOut(new PrintStream(new File("output.txt")));
System.out.println(r+" "+c);
}
} | cubic | 35_C. Fire Again | CODEFORCES |
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
public static InputStream IN;
public static OutputStream OUT;
public static PrintWriter out;
public static BufferedReader in;
public static StringTokenizer st = null;
public static int ni() throws Exception {
for (;st == null || !st.hasMoreTokens();){
st = new StringTokenizer(in.readLine());
}
return Integer.parseInt(st.nextToken());
}
public static void main(String[] args) throws Exception {
IN = new FileInputStream("input.txt");
OUT = new FileOutputStream("output.txt");
out = new PrintWriter(OUT);
in = new BufferedReader(new InputStreamReader(IN));
int n = ni();
int m = ni();
int k = ni();
int[] x = new int[k];
int[] y = new int[k];
for (int i = 0 ; i < k; i++){
x[i] = ni() - 1;
y[i] = ni() - 1;
}
int w = Integer.MIN_VALUE;
int aa = -1;
int ab = -1;
for (int i = 0 ; i < n ; i++){
for (int j = 0; j < m; j++){
int min = Integer.MAX_VALUE;
for (int q = 0; q < k; q++){
int cur = Math.abs(i - x[q]) + Math.abs(j - y[q]);
min = Math.min(cur, min);
}
if (min > w){
w = min;
aa = i;
ab = j;
}
}
}
out.println((aa + 1) + " " + (ab + 1));
out.flush();
}
}
| cubic | 35_C. Fire Again | CODEFORCES |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.