結果
| 問題 |
No.458 異なる素数の和
|
| ユーザー |
mban
|
| 提出日時 | 2016-12-22 14:17:46 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,867 bytes |
| コンパイル時間 | 1,190 ms |
| コンパイル使用メモリ | 111,312 KB |
| 実行使用メモリ | 197,600 KB |
| 最終ジャッジ日時 | 2024-12-14 14:25:28 |
| 合計ジャッジ時間 | 8,786 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 6 |
コンパイルメッセージ
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;
class Magatro
{
static int[] Primes;
static int N = int.Parse(Console.ReadLine());
static void Main()
{
PrimeCalc();
int[,] B = new int[N + 1, Primes.Length + 1];
for(int i = 0; i <= N; i++)
{
for(int j = 0; j <= Primes.Length;j++)
{
B[i, j] = -1;
}
}
B[0, 0] = 0;
for(int i = 0; i < Primes.Length; i++)
{
for(int j = 0; j <= N; j++)
{
if (B[j, i] == -1)
{
continue;
}
B[j, i + 1] = B[j, i];
if (j + Primes[i] > N)
{
continue;
}
B[j + Primes[i], i + 1] = B[j, i] + 1;
}
}
int max = -1;
for(int i = 1; i <= Primes.Length; i++)
{
max = Math.Max(max, B[N,i]);
}
Console.WriteLine(max);
}
static void PrimeCalc()
{
bool[] a = new bool[N + 1];
a[0] = true;
a[1] = true;
for(int i = 2; i <= Math.Sqrt(N); i++)
{
if (!a[i])
{
for(int j = i * 2; j <= N; j += i)
{
a[j] = true;
}
}
}
List<int> L = new List<int>();
for(int i = 0; i <= N; i++)
{
if (!a[i])
{
L.Add(i);
}
}
Primes = L.ToArray();
}
}
struct A
{
public A(int num,int cnt)
{
Num = num;
Cnt = cnt;
}
public int Num;
public int Cnt;
}
mban