Interviews are considered puzzles.

This commit is contained in:
2015-02-14 12:45:32 +04:00
parent 12af9d1b7f
commit 0f638a71f4
10 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/* Check cf5-opt.vim defs.
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
VIM-: let g:cppflags=g:Iboost.g:Itbb
VIM-: let g:ldflags=g:Lboost.g:Ltbb.g:tbbmalloc.g:tbbmproxy
VIM-: let g:ldlibpath=g:Bboost.g:Btbb
VIM: let g:argv=""
*/
#include <iostream>
#include <vector>
#include <stdexcept>
int main ( void )
{try{
//
// Read length.
//
long long n;
std::cin >> n;
if ( n < 4 )
throw std::runtime_error( "Input length is not enough." );
//
// Read seq.
//
typedef std::vector<int> arr_type;
arr_type arr(n);
for ( int& i: arr )
std::cin >> i;
//
// Solve it.
//
long long s = 0;
for ( long long i: arr )
s += i;
long long d = arr[1]-arr[0];
if ( d != arr[2]-arr[1] && d != arr[3]-arr[2])
d = arr[2]-arr[1];
long long idx = (n+1)*n/2-(s-n*arr[0])/d;
//
//
//
long long missing = arr[0]+idx*d;
std::cout << missing;
return 0;
}
catch ( const std::exception& e )
{
std::cerr << std::endl
<< "std::exception(\"" << e.what() << "\")." << std::endl;
return 2;
}
catch ( ... )
{
std::cerr << std::endl
<< "unknown exception." << std::endl;
return 1;
}}