Please sign in first.
Submission #64191286
Source Code Expand
using System;
using System.Diagnostics;
namespace cp;
internal static class Codeforces
{
private static int _d;
private static int[] _c;
private static int[,] _s;
private static readonly Random _random = new Random();
public static void Main()
{
_d = Convert.ToInt32(Console.ReadLine());
_c = Console.ReadLine()!.Split(' ').Select(int.Parse).ToArray();
Debug.Assert(_c.Length == 26);
_s = new int[_d, 26];
for (int i = 0; i < _d; i++)
{
IEnumerable<int> r = Console.ReadLine()!.Split(' ').Select(int.Parse);
IEnumerator<int> e = r.GetEnumerator();
for (int j = 0; j < 26; j++)
{
e.MoveNext();
_s[i, j] = e.Current;
}
Debug.Assert(!e.MoveNext());
}
// int[] bestSchedule = RunHillClimbing();
int[] bestSchedule = RunSA();
for (int i = 0; i < _d; i++)
{
Console.WriteLine(bestSchedule[i]);
}
}
private static int[] RunHillClimbing()
{
int bestScoreHc = int.MinValue;
// Initialize a random probably shitty schedule
int[] schedule = new int[_d];
for (int i = 0; i < _d; i++)
{
schedule[i] = _random.Next(1, 27);
}
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 1950)
{
int randomIdx = _random.Next(_d);
int oldScheduledContest = schedule[randomIdx];
int randomContest = _random.Next(1, 27);
schedule[randomIdx] = randomContest;
int newScore = EvaluateSchedule(schedule);
if (newScore > bestScoreHc)
{
bestScoreHc = newScore;
}
else
{
schedule[randomIdx] = oldScheduledContest;
}
}
return schedule;
}
private static int[] RunSA()
{
int bestScoreSa = int.MinValue;
int[] bestScheduleSa = new int[_d];
const float initialTemperature = 2000;
const float finalTemperature = 600;
// Initialize a random probably shitty schedule
int[] schedule = new int[_d];
for (int i = 0; i < _d; i++)
{
schedule[i] = _random.Next(1, 27);
}
Stopwatch stopwatch = Stopwatch.StartNew();
while (stopwatch.ElapsedMilliseconds < 1950)
{
// t_initial * pow(t_final / t_initial, elapsed() / time_limit)
float temperature = initialTemperature * (float)Math.Pow(
finalTemperature/initialTemperature,
stopwatch.ElapsedMilliseconds/1950f
);
int randomIdx = _random.Next(_d);
int oldScheduledContest = schedule[randomIdx];
int randomContest = _random.Next(1, 27);
while (randomContest == oldScheduledContest)
{
randomContest = _random.Next(1, 27);
}
schedule[randomIdx] = randomContest;
int newScore = EvaluateSchedule(schedule);
if (newScore > bestScoreSa)
{
bestScoreSa = newScore;
bestScheduleSa = (int[])schedule.Clone();
}
else
{
if (_random.NextDouble() < Math.Exp((newScore - bestScoreSa) / temperature))
{
bestScoreSa = newScore;
bestScheduleSa = (int[])schedule.Clone();
}
else
{
schedule[randomIdx] = oldScheduledContest;
}
}
}
return bestScheduleSa;
}
private static int EvaluateSchedule(int[] schedule)
{
Debug.Assert(schedule.Length == _d);
int[] last = new int[26];
int totSatisfaction = 0;
for (int i = 0; i < _d; i++)
{
int contest = schedule[i] - 1;
totSatisfaction += _s[i, contest];
last[contest] = i + 1;
for (int j = 0; j < 26; j++)
{
totSatisfaction -= _c[j] * (i + 1 - last[j]);
}
}
return totSatisfaction;
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | A - AtCoder Contest Scheduling |
| User | JasonMendoza2008 |
| Language | C# 11.0 AOT (.NET 7.0.7) |
| Score | 102377536 |
| Code Size | 4539 Byte |
| Status | AC |
| Exec Time | 1955 ms |
| Memory | 34868 KiB |
Judge Result
| Set Name | test_ALL | ||
|---|---|---|---|
| Score / Max Score | 102377536 / 365000000 | ||
| Status |
|
| Set Name | Test Cases |
|---|---|
| test_ALL | test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| test_00.txt | AC | 1955 ms | 34732 KiB |
| test_01.txt | AC | 1955 ms | 34752 KiB |
| test_02.txt | AC | 1954 ms | 34528 KiB |
| test_03.txt | AC | 1954 ms | 34700 KiB |
| test_04.txt | AC | 1954 ms | 34520 KiB |
| test_05.txt | AC | 1954 ms | 34688 KiB |
| test_06.txt | AC | 1954 ms | 34632 KiB |
| test_07.txt | AC | 1954 ms | 34868 KiB |
| test_08.txt | AC | 1954 ms | 34628 KiB |
| test_09.txt | AC | 1954 ms | 34568 KiB |
| test_10.txt | AC | 1955 ms | 34668 KiB |
| test_11.txt | AC | 1954 ms | 34524 KiB |
| test_12.txt | AC | 1954 ms | 34804 KiB |
| test_13.txt | AC | 1954 ms | 34864 KiB |
| test_14.txt | AC | 1954 ms | 34676 KiB |
| test_15.txt | AC | 1954 ms | 34652 KiB |
| test_16.txt | AC | 1954 ms | 34612 KiB |
| test_17.txt | AC | 1954 ms | 34628 KiB |
| test_18.txt | AC | 1954 ms | 34728 KiB |
| test_19.txt | AC | 1954 ms | 34568 KiB |
| test_20.txt | AC | 1954 ms | 34676 KiB |
| test_21.txt | AC | 1954 ms | 34596 KiB |
| test_22.txt | AC | 1955 ms | 34796 KiB |
| test_23.txt | AC | 1954 ms | 34624 KiB |
| test_24.txt | AC | 1954 ms | 34736 KiB |
| test_25.txt | AC | 1954 ms | 34684 KiB |
| test_26.txt | AC | 1954 ms | 34692 KiB |
| test_27.txt | AC | 1954 ms | 34804 KiB |
| test_28.txt | AC | 1954 ms | 34664 KiB |
| test_29.txt | AC | 1954 ms | 34836 KiB |
| test_30.txt | AC | 1954 ms | 34864 KiB |
| test_31.txt | AC | 1954 ms | 34804 KiB |
| test_32.txt | AC | 1954 ms | 34620 KiB |
| test_33.txt | AC | 1954 ms | 34684 KiB |
| test_34.txt | AC | 1954 ms | 34664 KiB |
| test_35.txt | AC | 1954 ms | 34596 KiB |
| test_36.txt | AC | 1954 ms | 34608 KiB |
| test_37.txt | AC | 1954 ms | 34604 KiB |
| test_38.txt | AC | 1954 ms | 34752 KiB |
| test_39.txt | AC | 1954 ms | 34604 KiB |
| test_40.txt | AC | 1954 ms | 34604 KiB |
| test_41.txt | AC | 1955 ms | 34800 KiB |
| test_42.txt | AC | 1954 ms | 34624 KiB |
| test_43.txt | AC | 1954 ms | 34800 KiB |
| test_44.txt | AC | 1954 ms | 34800 KiB |
| test_45.txt | AC | 1954 ms | 34804 KiB |
| test_46.txt | AC | 1954 ms | 34800 KiB |
| test_47.txt | AC | 1954 ms | 34624 KiB |
| test_48.txt | AC | 1954 ms | 34804 KiB |
| test_49.txt | AC | 1954 ms | 34608 KiB |