Submission #28091

# Submission time Handle Problem Language Result Execution time Memory
28091 2017-07-15T10:26:58 Z EyeOfSol(#1198, tlwpdus) The Ant and The Bitcoin (FXCUP2_ant) C++
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int n, l, t;

int mokx(int a, int b) {
	if (a>=0) return a/b;
	return (a-b+1)/b;
}

int loc(int a, int dir, int t) {
	int v = a*dir+t;
	if (mokx(v,l)%2) return l-(v%l+l)%l;
	return (v%l+l)%l;
}

int arr[100100], ord[100100];
vector<int> vec;

int main() {
	int i;
	scanf("%d%d%d",&n,&l,&t);
	for (i=0;i<n;i++) {
		char ch;
		ord[i] = i;
		scanf("%d %c",&arr[i],&ch);
		if (ch=='L') vec.push_back(loc(arr[i],-1,t));
		else vec.push_back(loc(arr[i],1,t));
	}
	sort(ord,ord+n,[](int a, int b){return arr[a]<arr[b];});
	int id;
	scanf("%d",&id); id--;
	int v = vec[id];
	sort(vec.begin(),vec.end());
	for (i=0;i<vec.size();i++) {
		if (vec[i]==v) printf("%d\n",ord[i]+1);
	}

    return 0;
}

Compilation message

ant.cpp: In function 'int main()':
ant.cpp:31:55: warning: lambda expressions only available with -std=c++11 or -std=gnu++11
  sort(ord,ord+n,[](int a, int b){return arr[a]<arr[b];});
                                                       ^
ant.cpp:31:56: error: no matching function for call to 'sort(int [100100], int*, main()::<lambda(int, int)>)'
  sort(ord,ord+n,[](int a, int b){return arr[a]<arr[b];});
                                                        ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:64,
                 from ant.cpp:1:
/usr/include/c++/5/bits/stl_algo.h:4689:5: note: candidate: template<class _RAIter> void std::sort(_RAIter, _RAIter)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
     ^
/usr/include/c++/5/bits/stl_algo.h:4689:5: note:   template argument deduction/substitution failed:
ant.cpp:31:56: note:   candidate expects 2 arguments, 3 provided
  sort(ord,ord+n,[](int a, int b){return arr[a]<arr[b];});
                                                        ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:64,
                 from ant.cpp:1:
/usr/include/c++/5/bits/stl_algo.h:4718:5: note: candidate: template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)
     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
     ^
/usr/include/c++/5/bits/stl_algo.h:4718:5: note:   template argument deduction/substitution failed:
ant.cpp: In substitution of 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = int*; _Compare = main()::<lambda(int, int)>]':
ant.cpp:31:56:   required from here
ant.cpp:31:56: error: template argument for 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)' uses local type 'main()::<lambda(int, int)>'
  sort(ord,ord+n,[](int a, int b){return arr[a]<arr[b];});
                                                        ^
ant.cpp:31:56: error:   trying to instantiate 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
ant.cpp:36:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0;i<vec.size();i++) {
            ^
ant.cpp:23:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&n,&l,&t);
                          ^
ant.cpp:27:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %c",&arr[i],&ch);
                             ^
ant.cpp:33:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&id); id--;
                 ^