Submission #103347


Source Code Expand

 
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, pair<int, int> > state;
 
/*
*/
 
#define INV -10000000
 
pair<int, pair<int, int> > memo[100][102][102];
int val[100];
vector<int> child[100];
 
int N;
 
state solve(int P, int alpha, int beta, bool sgn)
{
if(memo[P][alpha][beta].first != INV) return memo[P][alpha][beta];
if(child[P].size() == 0){
return memo[P][alpha][beta] = make_pair((sgn ? 1 : -1) * val[P], make_pair(1, 1));
}
vector<int> perm;
for(int i=0;i<child[P].size();i++) perm.push_back(i);
int rMin=100000000, rMax=-1;
int alpha_ = alpha, beta_ = beta;
int ret = -1;
//printf("%d %d %d\n", P, alpha, beta);
do{
//test
alpha = alpha_; beta = beta_;
int sMin = 0, sMax = 0;
if(sgn){
for(int _i=0;_i<child[P].size();_i++){ int i = perm[_i];
state tmp = solve(child[P][i], alpha, beta, !sgn);
alpha = max(alpha, tmp.first);
sMin += tmp.second.first;
sMax += tmp.second.second;
if(beta <= alpha) break;
}
rMin = min(rMin, sMin);
rMax = max(rMax, sMax);
ret = alpha;
}else{
for(int _i=0;_i<child[P].size();_i++){ int i = perm[_i];
state tmp = solve(child[P][i], alpha, beta, !sgn);
beta = min(beta, tmp.first);
sMin += tmp.second.first;
sMax += tmp.second.second;
if(beta <= alpha) break;
}
rMin = min(rMin, sMin);
rMax = max(rMax, sMax);
ret = beta;
}
}while(next_permutation(perm.begin(), perm.end()));
return memo[P][alpha_][beta_] = make_pair(ret, make_pair(rMin, rMax));
}
 
int main()
{
scanf("%d", &N);
for(int i=0;i<N;i++) scanf("%d", val+i);
for(int i=0;i<N;i++){
int k, t;
scanf("%d", &k);
for(;k--;){
scanf("%d", &t);
--t;
child[i].push_back(t);
}
}
vector<int> st;
for(int i=0;i<N;i++) st.push_back(val[i]);
st.push_back(-10000000);
st.push_back(10000000);
sort(st.begin(), st.end());
st.erase(unique(st.begin(), st.end()), st.end());
for(int i=0;i<N;i++) val[i] = lower_bound(st.begin(), st.end(), val[i]) - st.begin();
int K = st.size();
for(int i=0;i<N;i++)
for(int j=0;j<K;j++)
for(int k=0;k<K;k++) memo[i][j][k] = make_pair(INV, make_pair(0, 0));
pair<int, int> ret = solve(0, 0, K-1, true).second;
printf("%d %d\n", ret.first, ret.second);
return 0;
}

Submission Info

Submission Time
Task E - Optimal alpha beta pruning
User Operasan
Language C++ (GCC 4.4.7)
Score 0
Code Size 2213 Byte
Status WA
Exec Time 47 ms
Memory 13084 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:64: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:65: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:68: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
./Main.cpp:70: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
AC × 22
WA × 40
Set Name Test Cases
all 00_sample_00, 00_sample_01, 00_sample_02, 00_sample_03, 10_Random_002_001_001_001_00, 10_Random_003_001_001_001_12, 10_Random_004_001_001_001_03, 10_Random_007_003_003_003_06, 10_Random_009_003_002_003_04, 10_Random_010_003_003_003_01, 10_Random_010_004_004_004_05, 10_Random_014_004_003_004_02, 10_Random_019_009_002_009_09, 10_Random_037_015_003_015_07, 10_Random_040_014_004_014_14, 10_Random_041_017_005_017_13, 10_Random_048_021_004_021_08, 10_Random_051_018_007_017_11, 10_Random_076_031_006_030_10, 20_Binary_004_002_002_002_12, 20_Binary_005_003_002_003_00, 20_Binary_009_005_003_004_04, 20_Binary_013_007_004_005_08, 20_Binary_013_007_005_007_02, 20_Binary_015_008_005_008_06, 20_Binary_015_008_005_008_10, 20_Binary_016_008_005_005_16, 20_Binary_018_009_005_009_01, 20_Binary_023_012_005_012_05, 20_Binary_033_017_007_017_18, 20_Binary_041_021_009_021_09, 20_Binary_053_027_009_025_14, 20_Binary_057_029_010_029_13, 20_Binary_063_032_011_032_17, 20_Binary_100_050_011_049_15, 20_Binary_100_050_011_050_11, 20_Binary_100_050_012_046_03, 20_Binary_100_050_012_049_07, 20_Binary_100_050_012_050_19, 30_Skew_003_001_001_001_00, 30_Skew_006_001_001_001_04, 30_Skew_006_002_002_002_08, 30_Skew_008_004_002_004_01, 30_Skew_009_005_004_005_12, 30_Skew_013_001_001_001_16, 30_Skew_018_004_003_004_02, 30_Skew_021_003_002_003_06, 30_Skew_024_009_005_009_18, 30_Skew_030_002_002_002_09, 30_Skew_033_013_005_013_05, 30_Skew_057_027_004_027_10, 30_Skew_066_007_002_007_14, 30_Skew_072_036_006_034_13, 30_Skew_073_033_007_029_17, 30_Skew_100_044_010_041_15, 30_Skew_100_045_008_045_19, 30_Skew_100_048_005_046_11, 30_Skew_100_048_007_048_07, 30_Skew_100_052_005_052_03, 40_MaxCase_100_080_044_080_00, 80_Line_100_001_001_001_00, 90_teuchi_00
Case Name Status Exec Time Memory
00_sample_00 AC 41 ms 12972 KiB
00_sample_01 AC 39 ms 12960 KiB
00_sample_02 AC 39 ms 13084 KiB
00_sample_03 AC 39 ms 12956 KiB
10_Random_002_001_001_001_00 AC 38 ms 12960 KiB
10_Random_003_001_001_001_12 AC 41 ms 12968 KiB
10_Random_004_001_001_001_03 AC 40 ms 12916 KiB
10_Random_007_003_003_003_06 AC 39 ms 12960 KiB
10_Random_009_003_002_003_04 WA 40 ms 12960 KiB
10_Random_010_003_003_003_01 AC 38 ms 12960 KiB
10_Random_010_004_004_004_05 WA 39 ms 12916 KiB
10_Random_014_004_003_004_02 AC 38 ms 12964 KiB
10_Random_019_009_002_009_09 WA 41 ms 12916 KiB
10_Random_037_015_003_015_07 WA 40 ms 12956 KiB
10_Random_040_014_004_014_14 WA 41 ms 12956 KiB
10_Random_041_017_005_017_13 WA 45 ms 12960 KiB
10_Random_048_021_004_021_08 WA 41 ms 12972 KiB
10_Random_051_018_007_017_11 WA 42 ms 12960 KiB
10_Random_076_031_006_030_10 WA 40 ms 12956 KiB
20_Binary_004_002_002_002_12 AC 38 ms 12964 KiB
20_Binary_005_003_002_003_00 WA 39 ms 12968 KiB
20_Binary_009_005_003_004_04 WA 38 ms 12960 KiB
20_Binary_013_007_004_005_08 AC 39 ms 12968 KiB
20_Binary_013_007_005_007_02 WA 40 ms 12972 KiB
20_Binary_015_008_005_008_06 WA 38 ms 12960 KiB
20_Binary_015_008_005_008_10 WA 39 ms 12960 KiB
20_Binary_016_008_005_005_16 WA 37 ms 12916 KiB
20_Binary_018_009_005_009_01 WA 39 ms 12960 KiB
20_Binary_023_012_005_012_05 WA 41 ms 13084 KiB
20_Binary_033_017_007_017_18 AC 40 ms 12912 KiB
20_Binary_041_021_009_021_09 WA 40 ms 12916 KiB
20_Binary_053_027_009_025_14 WA 41 ms 12912 KiB
20_Binary_057_029_010_029_13 WA 40 ms 12960 KiB
20_Binary_063_032_011_032_17 WA 40 ms 12956 KiB
20_Binary_100_050_011_049_15 WA 40 ms 12968 KiB
20_Binary_100_050_011_050_11 WA 41 ms 12916 KiB
20_Binary_100_050_012_046_03 WA 39 ms 13080 KiB
20_Binary_100_050_012_049_07 WA 41 ms 12972 KiB
20_Binary_100_050_012_050_19 WA 41 ms 12964 KiB
30_Skew_003_001_001_001_00 AC 40 ms 12964 KiB
30_Skew_006_001_001_001_04 AC 41 ms 12900 KiB
30_Skew_006_002_002_002_08 AC 40 ms 12972 KiB
30_Skew_008_004_002_004_01 WA 39 ms 12956 KiB
30_Skew_009_005_004_005_12 WA 39 ms 12964 KiB
30_Skew_013_001_001_001_16 AC 42 ms 12904 KiB
30_Skew_018_004_003_004_02 WA 38 ms 12972 KiB
30_Skew_021_003_002_003_06 AC 39 ms 12952 KiB
30_Skew_024_009_005_009_18 WA 40 ms 12968 KiB
30_Skew_030_002_002_002_09 AC 43 ms 12900 KiB
30_Skew_033_013_005_013_05 WA 39 ms 12972 KiB
30_Skew_057_027_004_027_10 WA 41 ms 12972 KiB
30_Skew_066_007_002_007_14 WA 41 ms 12896 KiB
30_Skew_072_036_006_034_13 WA 40 ms 12960 KiB
30_Skew_073_033_007_029_17 WA 40 ms 12960 KiB
30_Skew_100_044_010_041_15 WA 41 ms 12960 KiB
30_Skew_100_045_008_045_19 WA 39 ms 12968 KiB
30_Skew_100_048_005_046_11 WA 41 ms 12968 KiB
30_Skew_100_048_007_048_07 WA 42 ms 12896 KiB
30_Skew_100_052_005_052_03 WA 40 ms 12968 KiB
40_MaxCase_100_080_044_080_00 AC 47 ms 12968 KiB
80_Line_100_001_001_001_00 AC 39 ms 12964 KiB
90_teuchi_00 AC 40 ms 12964 KiB