結果

問題 No.5017 Tool-assisted Shooting
ユーザー inani_waoninani_waon
提出日時 2023-07-16 15:50:38
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 5,235 bytes
コンパイル時間 7,199 ms
コンパイル使用メモリ 145,280 KB
実行使用メモリ 47,444 KB
スコア 392,687
平均クエリ数 359.02
最終ジャッジ日時 2023-07-16 15:51:00
合計ジャッジ時間 21,178 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
44,956 KB
testcase_01 AC 89 ms
44,976 KB
testcase_02 AC 86 ms
45,404 KB
testcase_03 AC 92 ms
44,744 KB
testcase_04 AC 89 ms
44,496 KB
testcase_05 AC 87 ms
45,252 KB
testcase_06 AC 94 ms
44,828 KB
testcase_07 AC 100 ms
44,900 KB
testcase_08 AC 85 ms
44,348 KB
testcase_09 AC 80 ms
44,832 KB
testcase_10 AC 85 ms
45,180 KB
testcase_11 AC 80 ms
44,852 KB
testcase_12 AC 80 ms
44,664 KB
testcase_13 AC 83 ms
45,236 KB
testcase_14 AC 82 ms
45,388 KB
testcase_15 AC 93 ms
45,092 KB
testcase_16 AC 114 ms
45,340 KB
testcase_17 AC 103 ms
44,532 KB
testcase_18 AC 101 ms
44,984 KB
testcase_19 AC 107 ms
45,352 KB
testcase_20 AC 83 ms
44,844 KB
testcase_21 AC 81 ms
44,780 KB
testcase_22 AC 80 ms
45,076 KB
testcase_23 AC 79 ms
45,036 KB
testcase_24 AC 86 ms
46,736 KB
testcase_25 AC 98 ms
46,988 KB
testcase_26 AC 81 ms
46,744 KB
testcase_27 AC 103 ms
44,780 KB
testcase_28 AC 84 ms
44,980 KB
testcase_29 AC 115 ms
45,044 KB
testcase_30 AC 78 ms
45,020 KB
testcase_31 AC 81 ms
45,016 KB
testcase_32 AC 82 ms
44,480 KB
testcase_33 AC 86 ms
45,172 KB
testcase_34 AC 109 ms
47,444 KB
testcase_35 AC 99 ms
47,084 KB
testcase_36 AC 92 ms
45,296 KB
testcase_37 AC 81 ms
44,600 KB
testcase_38 AC 86 ms
47,016 KB
testcase_39 AC 84 ms
44,992 KB
testcase_40 AC 84 ms
45,196 KB
testcase_41 AC 93 ms
44,844 KB
testcase_42 AC 99 ms
45,332 KB
testcase_43 AC 82 ms
44,888 KB
testcase_44 AC 115 ms
45,644 KB
testcase_45 AC 89 ms
44,908 KB
testcase_46 AC 84 ms
45,308 KB
testcase_47 AC 80 ms
44,616 KB
testcase_48 AC 80 ms
47,212 KB
testcase_49 AC 83 ms
47,104 KB
testcase_50 AC 78 ms
45,468 KB
testcase_51 AC 81 ms
44,532 KB
testcase_52 AC 93 ms
44,940 KB
testcase_53 AC 99 ms
45,244 KB
testcase_54 AC 82 ms
45,088 KB
testcase_55 AC 111 ms
47,128 KB
testcase_56 AC 80 ms
44,572 KB
testcase_57 AC 93 ms
45,160 KB
testcase_58 AC 103 ms
45,380 KB
testcase_59 AC 102 ms
45,044 KB
testcase_60 AC 90 ms
45,032 KB
testcase_61 AC 85 ms
44,568 KB
testcase_62 AC 95 ms
44,692 KB
testcase_63 AC 104 ms
45,516 KB
testcase_64 AC 82 ms
46,848 KB
testcase_65 AC 82 ms
46,612 KB
testcase_66 AC 83 ms
46,892 KB
testcase_67 AC 101 ms
45,040 KB
testcase_68 AC 79 ms
44,760 KB
testcase_69 AC 95 ms
44,744 KB
testcase_70 AC 100 ms
45,264 KB
testcase_71 AC 90 ms
45,328 KB
testcase_72 AC 94 ms
44,848 KB
testcase_73 AC 97 ms
46,740 KB
testcase_74 AC 86 ms
45,212 KB
testcase_75 AC 81 ms
45,216 KB
testcase_76 AC 101 ms
45,012 KB
testcase_77 AC 82 ms
44,916 KB
testcase_78 AC 79 ms
44,704 KB
testcase_79 AC 81 ms
45,076 KB
testcase_80 AC 107 ms
45,016 KB
testcase_81 AC 89 ms
46,896 KB
testcase_82 AC 97 ms
44,916 KB
testcase_83 AC 88 ms
44,784 KB
testcase_84 AC 87 ms
44,776 KB
testcase_85 AC 78 ms
44,832 KB
testcase_86 AC 100 ms
46,940 KB
testcase_87 AC 79 ms
44,888 KB
testcase_88 AC 81 ms
45,024 KB
testcase_89 AC 93 ms
44,788 KB
testcase_90 AC 93 ms
44,972 KB
testcase_91 AC 78 ms
44,824 KB
testcase_92 AC 115 ms
44,904 KB
testcase_93 AC 96 ms
45,204 KB
testcase_94 AC 100 ms
45,104 KB
testcase_95 AC 83 ms
46,612 KB
testcase_96 AC 77 ms
44,724 KB
testcase_97 AC 115 ms
45,368 KB
testcase_98 AC 84 ms
44,616 KB
testcase_99 AC 95 ms
44,780 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 118 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
/home/judge/data/code/Main.cs(136,17): warning CS8632: '#nullable' 注釈コンテキスト内のコードでのみ、Null 許容参照型の注釈を使用する必要があります。 [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

public class YukicoScore6
{
    public static void Main(string[] args)
    {
#if DEBUG
        // 入力ファイルを流し込んで使うときにフォーマット差を吸収する
        Console.ReadLine();
#endif
        var solver = new Solver();
        for (int turn = 0; turn < 1000; turn++)
        {
            var n = int.Parse(Console.ReadLine());
            if (n == -1) return;
            for (int j = 0; j < n; j++)
            {
                var nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var enemy = new Enemy(nums[0], nums[1], turn);
                solver.AddEnemy( nums[2], enemy);
            }
            var cmd = solver.GetCommand();
            Console.WriteLine(cmd);
            Console.Out.Flush();
            solver.ExecCommand(cmd);
        }
    }
}

public class Solver
{
    Random Random = new Random(1728);

    State State = new State();

    public string GetCommand()
    {
        var bestScore = int.MinValue;
        var bestX = State.PlayerX;
        var bestCmd = "S";
        for (int x = 0; x < Inputs.Width; x++)
        {
            var enemy = State.GetFirstEnemy(x);
            if (enemy == null) continue;

            var attackTurn = (int)Math.Ceiling(enemy.HP / (double)(State.PlayerLevel));
            // todo 衝突を回避する前提でターンを考える
            var moveTurn1 = Math.Abs(x - State.PlayerX);                                // ループしない
            var moveTurn2 = Math.Abs(0 - State.PlayerX) + Math.Abs(Inputs.Width - x);   // 左側へループ
            var moveTurn3 = Math.Abs(Inputs.Width - State.PlayerX) + Math.Abs(0 - x);   // 右側へループ
            var bestMoveTurn = Math.Min(Math.Min(moveTurn1, moveTurn2), moveTurn3);
            if (State.Turn + attackTurn + bestMoveTurn >= GetEnemyCollisionTurn(enemy)) continue;   // 倒すのが間に合わない
            var score = enemy.Power * 10000 / (attackTurn + bestMoveTurn);
            if (score > bestScore)
            {
                bestScore = score;
                bestX = x;
                if (moveTurn1 <= moveTurn2 && moveTurn1 <= moveTurn3)
                {

                    bestCmd = x == State.PlayerX ? "S" : (x < State.PlayerX ? "L" : "R");
                }
                else if (moveTurn2 <= moveTurn1 && moveTurn2 <= moveTurn3)
                {
                    bestCmd = "L";
                }
                else
                {
                    bestCmd = "R";
                }
            }
        }

        // todo 動かないときの衝突を回避する
        // todo 横向きに動いたときの衝突を回避する
        
        return bestCmd;
    }

    public void ExecCommand(string cmd)
    {
        State.Turn++;
        State.RemoveOldEnemy();
        if (cmd == "L") State.PlayerX = (State.PlayerX + Inputs.Width - 1) % Inputs.Width;
        if (cmd == "R") State.PlayerX = (State.PlayerX + 1) % Inputs.Width;

        var enemy = State.GetFirstEnemy(State.PlayerX);
        if (enemy == null) return;

        enemy.HP -= State.PlayerLevel;
        if (enemy.HP > 0) return;

        State.RemoveFirstEnemy(State.PlayerX);
        State.PlayerPower += enemy.Power;
        State.PlayerLevel = 1 + State.PlayerPower / 100;
    }

    public void AddEnemy(int x, Enemy enemy)
    {
        State.AddEnemy(x, enemy);
    }

    /// <summary>敵と自機が衝突するターンを取得する</summary>
    private int GetEnemyCollisionTurn(Enemy enemy)
    {
        return enemy.AppearanceTurn + Inputs.Height - 1;
    }
}

public class State
{
    public int Turn { get; set; }

    /// <summary>敵リスト</summary>
    public List<Enemy>[] Columns = new List<Enemy>[Inputs.Width];

    public int PlayerX { get; set; } = 12;
    public int PlayerPower { get; set; } = 0;
    public int PlayerLevel { get; set; } = 1;

    public State()
    {
        for (int i = 0; i < Inputs.Width; i++)
        {
            Columns[i] = new List<Enemy>();
        }
    }

    public void AddEnemy(int x, Enemy enemy)
    {
        Columns[x].Add(enemy);
    }

    public Enemy? GetFirstEnemy(int x)
    {
        if (!Columns[x].Any()) return null;
        return Columns[x][0];
    }

    public void RemoveOldEnemy()
    {
        for (int x = 0; x < Inputs.Width; x++)
        {
            if (!Columns[x].Any()) continue;
            var bottomEnemy = Columns[x][0];
            if (bottomEnemy.AppearanceTurn + Inputs.Height <= Turn)
            {
                Columns[x].RemoveAt(0);
            }
        }
    }

    public void RemoveFirstEnemy(int x)
    {
        Columns[x].RemoveAt(0);
    }
}

public class Inputs
{
    public const int Width = 25;
    public const int Height = 60;
}

public class Enemy
{
    public int InitHP { get; }
    public int HP { get; set; }
    public int Power { get; }
    /// <summary>出現ターン</summary>
    public int AppearanceTurn { get; }

    public Enemy(int initHP, int power, int appearanceTurn)
    {
        InitHP = initHP;
        HP = initHP;
        Power = power;
        AppearanceTurn = appearanceTurn;
    }
}
0