답안 #343175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343175 2021-01-03T13:14:12 Z Nursik Skyscraper (JOI16_skyscraper) C++14
15 / 100
443 ms 230764 KB
#include <bits/stdc++.h>
          
#define fi first
#define se second
#define pp pop_back
#define ll long long
#define pb push_back
#define ld long double
#define debug cout << "OK\n";
#define all(x) x.begin(), x.end() 
#define mp make_pair 
using namespace std;        
 
const ll N = 1e6;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll pe = mod2; 
const ll pe2 = 570210983;
const ld eps = 1e-6; 
 
 
/*
Rucode: jaqVYNrpMj
JUDGE_ID: 295965SY
dl:160532
*/
void data() {
	#ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
} 

int n, l, cur;
int a[30];
ll dp[2][15][20000][101];
vector<int> g[20];
vector<int> g2[20000];
main()
{
	data();
	ios_base::sync_with_stdio(0),
	cin.tie(0),cout.tie(0);	
	cin >> n >> l;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}       
	//optim
	for (int j = 0; j < (1 << n); j++)
	{
		g[__builtin_popcount(j)].pb(j);
		for (int i = 0; i < n; i ++)
		{
			if ((j & (1 << i)))
			{
			}
			else
			{
				g2[j].pb(i);
			}
		}	
	}
	//endoptim
	for (int i = 0; i < g[1].size(); i++)
	{
		int k = g[1][i], bit = 0;
		for (int j = 0; j < n; j++)
		{
			if (k >> j & 1)
				bit = j;	
		}
		dp[0][bit][k][0] = 1;
	}
	//cout << g2[0][0] << '\n';
	for (int i = 2; i <= n; i++)
	{
		for (int j = 0; j < g[i - 1].size(); j++)
		{
			int mask = g[i - 1][j];
			for (int k = 0; k < n; k++)
			{
				for (int sum = 0; sum <= l; sum++)
				{
					if (dp[cur][k][mask][sum] > 0)
					{              	
						
					//	cout << cur << " " << k << " " << mask << " " << sum << '\n';
						for (int ind = 0; ind < g2[mask].size(); ind++)
						{
							int nwbit = g2[mask][ind];
						//	cout << nwbit << '\n';
							if (sum + abs(a[k + 1] - a[nwbit + 1]) <= l)
							{
								dp[cur ^ 1][nwbit][(mask ^ (1 << nwbit))][sum + abs(a[k + 1] - a[nwbit + 1])] += dp[cur][k][mask][sum];
						    	dp[cur ^ 1][nwbit][(mask ^ (1 << nwbit))][sum + abs(a[k + 1] - a[nwbit + 1])] %= mod;
							}
						//	return 0;
						}
						dp[cur][k][mask][sum] = 0;     
					//	debug;
					//	return 0;
					}
				}
			}
		}
		cur ^= 1;
	}
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= l; j++)
		{
			ans += dp[cur][i][(1 << n) - 1][j];
			ans %= mod;
		}
	}
	cout << ans;

}
/*
6 4 2
2 9 2 3 8 5




*/

Compilation message

skyscraper.cpp:39:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   39 | main()
      |      ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for (int i = 0; i < g[1].size(); i++)
      |                  ~~^~~~~~~~~~~~~
skyscraper.cpp:78:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   for (int j = 0; j < g[i - 1].size(); j++)
      |                   ~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:89:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |       for (int ind = 0; ind < g2[mask].size(); ind++)
      |                         ~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Incorrect 4 ms 2300 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 51436 KB Output is correct
2 Correct 232 ms 168556 KB Output is correct
3 Correct 364 ms 229356 KB Output is correct
4 Correct 199 ms 153324 KB Output is correct
5 Correct 173 ms 101492 KB Output is correct
6 Correct 358 ms 230636 KB Output is correct
7 Correct 164 ms 126200 KB Output is correct
8 Correct 352 ms 229228 KB Output is correct
9 Correct 443 ms 230764 KB Output is correct
10 Correct 191 ms 141164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Incorrect 4 ms 2300 KB Output isn't correct
6 Halted 0 ms 0 KB -