Submission #2326032


Source Code Expand

import math
import numpy
import random
from datetime import datetime


def coord(n, x, y):
    return int(x + n * y + 1)


def probability(e1, e2, temp):
    if (e1 >= e2):
        return 1
    else:
        return math.exp((e1 - e2) / temp)


def temperature(r):
    return 0.8101919 ** r


start = datetime.now()
s = input().split()
V = int(s[0]);
E = int(s[1])
u = [0 for i in range(E)]
v = [0 for i in range(E)]
mat = [[0 for i in range(V)] for i in range(V)]
node = [0 for i in range(V)]
for i in range(E):
    s = input().split()
    u[i] = int(s[0]) - 1;
    v[i] = int(s[1]) - 1
    node[u[i]] += 1
    node[v[i]] += 1
ns = list(numpy.argsort(numpy.array(node)))
s = input().split()
Vemb = int(s[0]);
Eemb = int(s[1])
for i in range(Eemb):
    st = input()
out = [0 for i in range(V)]
outtemp = [0 for i in range(V)]
outbest = [0 for i in range(V)]
n = int(math.sqrt(Vemb))
i = n // 2 - 1
j = n // 2 - 1
di = 1
dj = 0
m = 1
for k in range(V):
    out[V - 1 - ns[k]]=(coord(n, i, j))
    outtemp[V - 1 - ns[k]]=(coord(n, i, j))
    outbest[V - 1 - ns[k]]=(coord(n, i, j))
    if (m * m + 1 == k + 1):
        dj = (m % 2) * 2 - 1
        di = 0
        m += 1
    elif (m * m - m + 1 == k + 1):
        di = (m % 2) * 2 - 1
        dj = 0
    i += di
    j += dj
nowtime = datetime.now()
pointnext = 5000
pointmax = 5000
point = 5000
flag = 1
for i in range(E):
    j = out[u[i]]
    k = out[v[i]]
    jx = j % n
    jy = j // n
    kx = k % n
    ky = k // n
    dx = jx - kx;
    dy = jy - ky
    if (dx == -1 or dx == 0 or dx == 1) and (dy == -1 or dy == 0 or dy == 1):
        point += 100
    else:
        flag = 0
if flag == 1:
    point += 100000
while ((nowtime - start).total_seconds() < 29):
    time = (nowtime - start).total_seconds() / 29
    p = random.randrange(V)
    q = random.randrange(V)
    if (p == q):
        while (1 == 1):
            p = random.randrange(V)
            q = random.randrange(V)
            if (p != q):
                break
    outpq = outtemp[p]
    outtemp[p]=outtemp[q]
    outtemp[q]=outpq
    pointnext = 5000
    flag = 1
    for i in range(E):
        j = outtemp[u[i]]
        k = outtemp[v[i]]
        jx = j % n
        jy = j // n
        kx = k % n
        ky = k // n
        dx = jx - kx;
        dy = jy - ky
        if (dx == -1 or dx == 0 or dx == 1) and (dy == -1 or dy == 0 or dy == 1):
             pointnext += 100
        else:
            flag = 0
    if flag == 1:
        pointnext += 100000
    if (pointmax < pointnext):
        for i in range(V):
            outbest[i]=outtemp[i]
        pointmax = pointnext
    if random.random() <= probability(pointnext, point, temperature(time)):
        point = pointnext
        for i in range(V):
            out[i]=outtemp[i]
    for i in range(V):
        outtemp[i]=out[i]
    nowtime = datetime.now()
for i in range(V):
    print("1 {0}".format(outbest[i]))

Submission Info

Submission Time
Task A - Problem 2
User shakayami
Language Python (3.4.3)
Score 1474600
Code Size 3010 Byte
Status AC
Exec Time 29173 ms
Memory 17564 KB

Judge Result

Set Name sample_00 sample_01 random_00 random_01 random_02 random_03 random_04 random_05 random_06 random_07 random_08 random_09 random_10 random_11 random_12 random_13 random_14 random_15 random_16 random_17 random_18 random_19 random_20 random_21 random_22 random_23 random_24 random_25 random_26 random_27
Score / Max Score 6200 / 1000000 7100 / 1000000 17800 / 1000000 31700 / 1000000 107000 / 1000000 55400 / 1000000 20700 / 1000000 7400 / 1000000 67500 / 1000000 59800 / 1000000 41400 / 1000000 65700 / 1000000 82200 / 1000000 17000 / 1000000 44300 / 1000000 85100 / 1000000 81900 / 1000000 72400 / 1000000 40200 / 1000000 64400 / 1000000 16000 / 1000000 63400 / 1000000 65000 / 1000000 45400 / 1000000 72000 / 1000000 40100 / 1000000 34300 / 1000000 21200 / 1000000 69600 / 1000000 72400 / 1000000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
sample_00 00_sample_00
sample_01 00_sample_01
random_00 10_random_00
random_01 10_random_01
random_02 10_random_02
random_03 10_random_03
random_04 10_random_04
random_05 10_random_05
random_06 10_random_06
random_07 10_random_07
random_08 10_random_08
random_09 10_random_09
random_10 10_random_10
random_11 10_random_11
random_12 10_random_12
random_13 10_random_13
random_14 10_random_14
random_15 10_random_15
random_16 10_random_16
random_17 10_random_17
random_18 10_random_18
random_19 10_random_19
random_20 10_random_20
random_21 10_random_21
random_22 10_random_22
random_23 10_random_23
random_24 10_random_24
random_25 10_random_25
random_26 10_random_26
random_27 10_random_27
Case Name Status Exec Time Memory
00_sample_00 AC 29170 ms 16776 KB
00_sample_01 AC 29154 ms 14860 KB
10_random_00 AC 29154 ms 14864 KB
10_random_01 AC 29157 ms 14988 KB
10_random_02 AC 29154 ms 14860 KB
10_random_03 AC 29163 ms 17164 KB
10_random_04 AC 29155 ms 14860 KB
10_random_05 AC 29155 ms 14860 KB
10_random_06 AC 29162 ms 16396 KB
10_random_07 AC 29163 ms 16396 KB
10_random_08 AC 29156 ms 15372 KB
10_random_09 AC 29157 ms 15628 KB
10_random_10 AC 29166 ms 16104 KB
10_random_11 AC 29156 ms 14864 KB
10_random_12 AC 29160 ms 15116 KB
10_random_13 AC 29160 ms 13836 KB
10_random_14 AC 29168 ms 15884 KB
10_random_15 AC 29160 ms 17040 KB
10_random_16 AC 29155 ms 15116 KB
10_random_17 AC 29165 ms 17432 KB
10_random_18 AC 29156 ms 14860 KB
10_random_19 AC 29166 ms 16272 KB
10_random_20 AC 29161 ms 15372 KB
10_random_21 AC 29159 ms 16504 KB
10_random_22 AC 29173 ms 17564 KB
10_random_23 AC 29157 ms 15116 KB
10_random_24 AC 29157 ms 15760 KB
10_random_25 AC 29156 ms 14992 KB
10_random_26 AC 29161 ms 15372 KB
10_random_27 AC 29158 ms 15628 KB