Submission #124180

# Submission time Handle Problem Language Result Execution time Memory
124180 2019-07-02T15:23:58 Z mechfrog88 Safety (NOI18_safety) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;	


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a;
	cin >> n >> a;
	if (n <= 14){
		vector <ll> arr(n+1,0);
		ll maxi = 0;
		for (int z=1;z<=n;z++){
			cin >> arr[z];
			maxi = max(maxi,arr[z]);
		}
		vector <vector<ll>> dp(n+1,vector<ll>(maxi+1,0));
		for (ll z=1;z<=n;z++){
			for (ll h=0;h<=maxi;h++){
				ll mini = LLONG_MAX;
				for (ll x=max(ll(0),h-a);x<=min(maxi,h+a);x++){
					mini = min(mini,dp[z-1][x]);
				}
				dp[z][h] = mini+abs(arr[z]-h);
			}
		}
		ll mini = LLONG_MAX;
		for(ll z=0;z<=maxi;z++){
	
				mini = min(dp[n][z],mini);
			}
		cout << mini << endl;
	} else {
		cout << 1 << endl;
	}

}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:7:2: error: 'ios_base' has not been declared
  ios_base::sync_with_stdio(false);
  ^~~~~~~~
safety.cpp:8:2: error: 'cin' was not declared in this scope
  cin.tie(NULL);
  ^~~
safety.cpp:8:2: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:75:0,
                 from safety.cpp:1:
/usr/include/c++/7/iostream:60:18: note:   'std::cin'
   extern istream cin;  /// Linked to standard input
                  ^~~
safety.cpp:12:3: error: 'vector' was not declared in this scope
   vector <ll> arr(n+1,0);
   ^~~~~~
safety.cpp:12:3: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:86,
                 from safety.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
safety.cpp:12:13: error: expected primary-expression before '>' token
   vector <ll> arr(n+1,0);
             ^
safety.cpp:12:15: error: 'arr' was not declared in this scope
   vector <ll> arr(n+1,0);
               ^~~
safety.cpp:16:11: error: 'max' was not declared in this scope
    maxi = max(maxi,arr[z]);
           ^~~
safety.cpp:16:11: note: suggested alternative:
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   'std::max'
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
safety.cpp:18:20: error: expected primary-expression before '>>' token
   vector <vector<ll>> dp(n+1,vector<ll>(maxi+1,0));
                    ^~
safety.cpp:18:39: error: expected primary-expression before '>' token
   vector <vector<ll>> dp(n+1,vector<ll>(maxi+1,0));
                                       ^
safety.cpp:18:45: warning: left operand of comma operator has no effect [-Wunused-value]
   vector <vector<ll>> dp(n+1,vector<ll>(maxi+1,0));
                                         ~~~~^~
safety.cpp:18:23: error: 'dp' was not declared in this scope
   vector <vector<ll>> dp(n+1,vector<ll>(maxi+1,0));
                       ^~
safety.cpp:22:15: error: 'max' was not declared in this scope
     for (ll x=max(ll(0),h-a);x<=min(maxi,h+a);x++){
               ^~~
safety.cpp:22:15: note: suggested alternative:
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   'std::max'
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
safety.cpp:22:33: error: 'min' was not declared in this scope
     for (ll x=max(ll(0),h-a);x<=min(maxi,h+a);x++){
                                 ^~~
safety.cpp:22:33: note: suggested alternative:
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   'std::min'
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
safety.cpp:31:12: error: 'min' was not declared in this scope
     mini = min(dp[n][z],mini);
            ^~~
safety.cpp:31:12: note: suggested alternative:
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from safety.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   'std::min'
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
safety.cpp:33:3: error: 'cout' was not declared in this scope
   cout << mini << endl;
   ^~~~
safety.cpp:33:3: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:75:0,
                 from safety.cpp:1:
/usr/include/c++/7/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^~~~
safety.cpp:33:19: error: 'endl' was not declared in this scope
   cout << mini << endl;
                   ^~~~
safety.cpp:33:19: note: suggested alternative:
In file included from /usr/include/c++/7/istream:39:0,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from safety.cpp:1:
/usr/include/c++/7/ostream:590:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^~~~
safety.cpp:35:3: error: 'cout' was not declared in this scope
   cout << 1 << endl;
   ^~~~
safety.cpp:35:3: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:75:0,
                 from safety.cpp:1:
/usr/include/c++/7/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^~~~
safety.cpp:35:16: error: 'endl' was not declared in this scope
   cout << 1 << endl;
                ^~~~
safety.cpp:35:16: note: suggested alternative:
In file included from /usr/include/c++/7/istream:39:0,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from safety.cpp:1:
/usr/include/c++/7/ostream:590:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^~~~