結果
| 問題 | No.15 カタログショッピング | 
| コンテスト | |
| ユーザー |  mban | 
| 提出日時 | 2017-07-20 14:34:52 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 3,350 bytes | 
| コンパイル時間 | 1,977 ms | 
| コンパイル使用メモリ | 112,136 KB | 
| 実行使用メモリ | 38,748 KB | 
| 最終ジャッジ日時 | 2024-10-08 17:42:53 | 
| 合計ジャッジ時間 | 3,955 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 RE * 7 | 
コンパイルメッセージ
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 left1 = 0, right1 = B.Count;
        while (right1 - left1 > 1)
        {
            int mid = (left1 + right1) / 2;
            if (B[mid].Price > S - s.Price)
            {
                right1 = mid;
            }
            else
            {
                left1 = mid;
            }
        }
        int left2 = -1, right2 = B.Count - 1;
        while (right2 - left2 > 1)
        {
            int mid = (left2 + right2) / 2;
            if (B[mid].Price >= S - s.Price)
            {
                right2 = mid;
            }
            else
            {
                left2 = mid;
            }
        }
        if (B[left1].Price == S - s.Price)
        {
            //Console.WriteLine("{2} {0} {1}", left2 + 1, left1,s.Price);
            for (int i = left2 + 1; i <= left1; i++)
            {
                List<int> ans = new List<int>();
                for (int j = 0; j < N; j++)
                {
                    if (s.Use[j] || B[i].Use[j])
                    {
                        ans.Add(j + 1);
                    }
                }
                Anser.AppendLine(string.Join(" ", ans));
            }
        }
    }
    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])
                {
                    return -1;
                }
                if (b.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());
    }
}
            
            
            
        