結果
| 問題 |
No.580 旅館の予約計画
|
| ユーザー |
threecourse
|
| 提出日時 | 2018-05-17 14:56:09 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 3,015 bytes |
| コンパイル時間 | 898 ms |
| コンパイル使用メモリ | 108,928 KB |
| 実行使用メモリ | 27,184 KB |
| 最終ジャッジ日時 | 2024-06-28 13:30:05 |
| 合計ジャッジ時間 | 3,237 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 36 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Competitive
{
internal class Solution
{
public int N, M;
public Data[] D;
public int[] R;
public void Run()
{
// Input
{
var line = Input.ReadIntArray();
N = line[0];
M = line[1];
}
D = new Data[M];
for (int i = 0; i < M; i++)
{
var line = Console.ReadLine();
D[i] = new Data(line);
}
// Sort
Array.Sort(D, (d1, d2) => (d1.O.CompareTo(d2.O)));
// Set Rooms
R = new int[N];
for (int i = 0; i < N; i++) R[i] = -1;
// Solve
int ret = 0;
for (int i = 0; i < M; i++)
{
int last_room = -1;
int last_t = -2;
for (int j = 0; j < N; j++)
{
// チェックイン時刻には空いており、かつ条件を満たす者の中で最も遅い
if (R[j] < D[i].I && R[j] > last_t)
{
last_room = j;
last_t = R[j];
}
}
if (last_room != -1)
{
R[last_room] = D[i].O;
ret++;
}
}
Console.WriteLine(ret);
}
}
// libs ----------
class Data
{
public int I, O;
public Data(string line)
{
int ID = int.Parse(line.Substring(0, 1));
int IH = int.Parse(line.Substring(2, 2));
int IM = int.Parse(line.Substring(5, 2));
int OD = int.Parse(line.Substring(8, 2));
int OH = int.Parse(line.Substring(10, 2));
int OM = int.Parse(line.Substring(13, 2));
I = ID * 24 * 60 + IH * 60 + IM;
O = OD * 24 * 60 + OH * 60 + OM;
}
}
// common ----------
internal static class Input
{
public static int ReadInt()
{
string line = Console.ReadLine();
return int.Parse(line);
}
public static int[] ReadIntArray()
{
string line = Console.ReadLine();
return line.Split(' ').Select(int.Parse).ToArray();
}
public static double[] ReadDoubleArray()
{
string line = Console.ReadLine();
return line.Split(' ').Select(double.Parse).ToArray();
}
public static long[] ReadLongArray()
{
string line = Console.ReadLine();
return line.Split(' ').Select(long.Parse).ToArray();
}
}
internal class Program
{
public static void Main(string[] args)
{
var s = new Solution();
s.Run();
}
}
}
threecourse