結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  mban | 
| 提出日時 | 2017-07-20 15:04:22 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 98 ms / 5,000 ms | 
| コード長 | 2,902 bytes | 
| コンパイル時間 | 3,500 ms | 
| コンパイル使用メモリ | 113,728 KB | 
| 実行使用メモリ | 37,728 KB | 
| 最終ジャッジ日時 | 2024-10-08 17:43:59 | 
| 合計ジャッジ時間 | 4,908 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}
struct S
{
    public bool[] Use;
    public long Price;
    public S(long p, bool[] u)
    {
        Price = p;
        Use = u;
    }
}
class Magatro
{
    private int N;
    private long S;
    private long[] P;
    private List<S> A = new List<S>(), B = new List<S>();
    private StringBuilder Anser = new StringBuilder();
    private void Scan()
    {
        var ns = Console.ReadLine().Split(' ');
        N = int.Parse(ns[0]);
        S = long.Parse(ns[1]);
        P = new long[N];
        for (int i = 0; i < N; i++)
        {
            P[i] = long.Parse(Console.ReadLine());
        }
    }
    private void D(int left, int right, long sum, bool[] use, List<S> t)
    {
        if (left >= right)
        {
            t.Add(new S(sum, use.ToArray()));
            return;
        }
        D(left + 1, right, sum, use, t);
        if (sum + P[left] <= S)
        {
            use[left] = true;
            D(left + 1, right, sum + P[left], use, t);
            use[left] = false;
        }
    }
    private void Search(S s)
    {
        int left = -1;
        int right = B.Count - 1;
        while (right - left > 1)
        {
            int mid = (left + right) / 2;
            if (B[mid].Price >= S - s.Price)
            {
                right = mid;
            }
            else
            {
                left = mid;
            }
        }
        for (int i = right; i < B.Count && B[i].Price == S - s.Price; i++)
        {
            var list = new List<int>();
            for (int j = 0; j < N; j++)
            {
                if (s.Use[j] || B[i].Use[j])
                {
                    list.Add(j + 1);
                }
            }
            Anser.AppendLine(string.Join(" ", list));
        }
    }
    public void Solve()
    {
        Scan();
        D(0, N / 2, 0, new bool[N], A);
        D(N / 2, N, 0, new bool[N], B);
        A.Sort((a, b) =>
        {
            for (int i = 0; i < N; i++)
            {
                if (a.Use[i] && !b.Use[i])
                {
                    return -1;
                }
                if (b.Use[i] && !a.Use[i])
                {
                    return 1;
                }
            }
            return 0;
        });
        B.Sort((a, b) =>
        {
            if (a.Price != b.Price)
            {
                return a.Price.CompareTo(b.Price);
            }
            return Array.IndexOf(a.Use, true).CompareTo(Array.IndexOf(b.Use, true));
        });
        foreach (var s in A)
        {
            Search(s);
        }
        Console.Write(Anser.ToString());
    }
}
            
            
            
        