Submission #16647552


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <utility>
#include <chrono>
using namespace std;
constexpr int V_MAX = 500;
constexpr int Vemb_MAX = 3600;
static int emb[Vemb_MAX] = {}, inv[V_MAX] = {};
vector<pair<int, int>> G[V_MAX];
vector<int> Gemb[Vemb_MAX];
static int weight[V_MAX][V_MAX] = {};
static bool isEemb[Vemb_MAX][Vemb_MAX] = {};
chrono::system_clock::time_point start;
constexpr int timeLimit = 9900;
int V, E, Vemb, Eemb;
int CalcScore()
{
int score = 0;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>
#include <vector>
#include <utility>
#include <chrono>
using namespace std;

constexpr int V_MAX = 500;
constexpr int Vemb_MAX = 3600;

static int emb[Vemb_MAX] = {}, inv[V_MAX] = {};
vector<pair<int, int>> G[V_MAX];
vector<int> Gemb[Vemb_MAX];
static int weight[V_MAX][V_MAX] = {};
static bool isEemb[Vemb_MAX][Vemb_MAX] = {};
chrono::system_clock::time_point start;
constexpr int timeLimit = 9900;

int V, E, Vemb, Eemb;
int CalcScore()
{
    int score = 0;
    for (int now = 500; now < Vemb; now++)
    {
        if (emb[now] == -1)
            continue;
        for (int next : Gemb[now])
            if (emb[next] != -1)
                score += weight[emb[now]][emb[next]];
    }
    return score / 2;
}

inline int RandXor()
{
    static unsigned int x = 123456789, y = 987235098, z = 957398509, w = 879423879;
    unsigned int t;
    t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return abs((int)w);
}
int main()
{
    start = chrono::system_clock::now();
    cin >> V >> E;
    for (int i = 0; i < E; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        G[u].emplace_back(v, w);
        G[v].emplace_back(u, w);
        weight[u][v] = weight[v][u] = w;
    }
    cin >> Vemb >> Eemb;
    for (int i = 0; i < Eemb; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        Gemb[a].emplace_back(b);
        Gemb[b].emplace_back(a);
        isEemb[a][b] = isEemb[b][a] = true;
    }

    for (int i = 0; i < Vemb_MAX; i++)
        emb[i] = -1;
    for (int i = 0; i < V; i++)
        emb[i] = i;
    for (int i = 0; i < V_MAX; i++)
        inv[i] = -1;
    for (int i = 0; i < V; i++)
        inv[i] = i;

    int nowTime = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
    int nowScore = CalcScore();
    while (nowTime < timeLimit)
    {
        //適当に入れ替える
        int a = RandXor() % V, b = RandXor() % V;
        swap(emb[inv[a]], emb[inv[b]]);

        int nextScore = CalcScore();
        if (nextScore < nowScore) //まだ山登り
        {
            swap(emb[inv[a]], emb[inv[b]]);
            continue;
        }
        else
        {
            swap(inv[a], inv[b]);
            nowScore = nextScore;
        }

        nowTime = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
    }

    for (int i = 0; i < V; i++)
        cout << i + 1 << " " << inv[i] + 1 << endl;

    return 0;
}

Submission Info

Submission Time
Task A - Problem 1
User takeo1116
Language C++ (GCC 9.2.1)
Score 49034
Code Size 2639 Byte
Status AC
Exec Time 9910 ms
Memory 5308 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 full_00 full_01 full_02 full_03 full_04 full_05 full_06 full_07 full_08 sparse_00 sparse_01 sparse_02 sparse_03 sparse_04 sparse_05 sparse_06 sparse_07 random_max full_max
Score / Max Score 3 / 1000000 45 / 1000000 710 / 1000000 3787 / 1000000 2041 / 1000000 3438 / 1000000 175 / 1000000 1687 / 1000000 2447 / 1000000 2391 / 1000000 3112 / 1000000 4269 / 1000000 2518 / 1000000 91 / 1000000 948 / 1000000 2658 / 1000000 5146 / 1000000 551 / 1000000 2208 / 1000000 2463 / 1000000 161 / 1000000 185 / 1000000 108 / 1000000 107 / 1000000 274 / 1000000 31 / 1000000 164 / 1000000 121 / 1000000 2207 / 1000000 4988 / 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
full_00 20_full_00
full_01 20_full_01
full_02 20_full_02
full_03 20_full_03
full_04 20_full_04
full_05 20_full_05
full_06 20_full_06
full_07 20_full_07
full_08 20_full_08
sparse_00 30_sparse_00
sparse_01 30_sparse_01
sparse_02 30_sparse_02
sparse_03 30_sparse_03
sparse_04 30_sparse_04
sparse_05 30_sparse_05
sparse_06 30_sparse_06
sparse_07 30_sparse_07
random_max 60_random_max_00
full_max 70_full_max_00
Case Name Status Exec Time Memory
00_sample_00 AC 9907 ms 3492 KB
00_sample_01 AC 9903 ms 3680 KB
10_random_00 AC 9903 ms 3716 KB
10_random_01 AC 9904 ms 4584 KB
10_random_02 AC 9907 ms 5184 KB
10_random_03 AC 9903 ms 4264 KB
10_random_04 AC 9902 ms 3708 KB
10_random_05 AC 9903 ms 4640 KB
10_random_06 AC 9907 ms 4536 KB
10_random_07 AC 9903 ms 4024 KB
10_random_08 AC 9903 ms 4116 KB
20_full_00 AC 9903 ms 4392 KB
20_full_01 AC 9905 ms 3968 KB
20_full_02 AC 9903 ms 3708 KB
20_full_03 AC 9902 ms 3808 KB
20_full_04 AC 9903 ms 3812 KB
20_full_05 AC 9903 ms 4324 KB
20_full_06 AC 9902 ms 3776 KB
20_full_07 AC 9902 ms 3964 KB
20_full_08 AC 9902 ms 3840 KB
30_sparse_00 AC 9908 ms 4748 KB
30_sparse_01 AC 9902 ms 3948 KB
30_sparse_02 AC 9904 ms 4552 KB
30_sparse_03 AC 9909 ms 4360 KB
30_sparse_04 AC 9903 ms 4384 KB
30_sparse_05 AC 9903 ms 4248 KB
30_sparse_06 AC 9910 ms 4532 KB
30_sparse_07 AC 9905 ms 3776 KB
60_random_max_00 AC 9910 ms 5308 KB
70_full_max_00 AC 9904 ms 4528 KB


2025-04-07 (Mon)
05:53:22 +00:00