제출 #896883

#제출 시각아이디문제언어결과실행 시간메모리
896883Litusiano순열 (APIO22_perm)C++17
컴파일 에러
0 ms0 KiB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma") #include<bits/stdc++.h> #include "perm.h" using namespace std; mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); vector<int> shuffle(vector<int>& v){ int sz = v.size(); for(int i = 0; i < 2 * v.size(); i++){ int a = rng()%sz; int b = rng()%sz; swap(v[a],v[b]); } return v; } long long getdp(vector<int>& v, long long MX) { vector<long long> dp(v.size() + 1, 0); dp[0] = 1; for (int x : v) { for (int i = 0; i <= x; i++) { dp[x+1] += dp[i]; dp[x+1] = min(dp[x+1],MX+1); if(dp[x+1] == MX+1) return MX+1; } } long long result = 0; for (int i = 0; i <= (int)v.size(); i++){ result += dp[i]; result = min(result,MX+1); } return result; } vector<int> construct_permutation(long long k) { int z = 0; const int CT = 1; if(k <= 90){ vector<int> v; for(int i = k-2; i>=0; i--){ v.push_back(i); } return v; } vector<int> v; for(int a = 1; a<=90; a++){ v.push_back(a-1); if(a >= 7){ z+= CT * a * a; for(int _ = 0; _ < CT; _++){ v = shuffle(v); if(getdp(v,k) == k){ return v; } } } else{ int f = 1; for(int i = 1; i<=a; i++) f*=i; z+= f * a * a; sort(v.begin(),v.end()); do{ if(getdp(v,k) == k) return v; }while(next_permutation(v.begin(),v.end())); } } // cerr<<z*100ll<<endl; return v; } static long long MX=1e18; static bool check_permutation(vector<int> v) { sort(v.begin(),v.end()); for(int i=0;i<v.size();i++) if(v[i]!=i) return 0; return 1; } long long count_increasing(const vector<int>& v) { vector<long long> dp(v.size() + 1, 0); dp[0] = 1; for (int x : v) { for (int i = 0; i <= x; i++) { dp[x+1] += dp[i]; dp[x+1] = min(dp[x+1],MX+1); } } long long result = 0; for (int i = 0; i <= (int)v.size(); i++){ result += dp[i]; result = min(result,MX+1); } return result; } int main() { int t; assert(1 == scanf("%d", &t)); while(t--) { long long k; assert(1 == scanf("%lld",&k)); vector<int> ret=construct_permutation(k); // for(int i : ret) cout<<i<<" "; // cout<<endl; if(!check_permutation(ret)) { printf("WA: Returned array is not a permutation\n"); exit(0); } long long inc=count_increasing(ret); if(inc!=k) { if(inc==MX+1) printf("WA: Expected %lld increasing subsequences, found more than %lld\n",k, MX); else printf("WA: Expected %lld increasing subsequences, found %lld\n",k,inc); exit(0); } printf("%d\n",(int)ret.size()); for(int i=0;i<ret.size();i++) { printf("%d",ret[i]); if(i+1==ret.size()) printf("\n"); else printf(" "); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

perm.cpp: In function 'std::vector<int> shuffle(std::vector<int>&)':
perm.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0; i < 2 * v.size(); i++){
      |                 ~~^~~~~~~~~~~~~~
perm.cpp: In function 'bool check_permutation(std::vector<int>)':
perm.cpp:82:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for(int i=0;i<v.size();i++)
      |              ~^~~~~~~~~
perm.cpp: In function 'int main()':
perm.cpp:131:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |   for(int i=0;i<ret.size();i++)
      |               ~^~~~~~~~~~~
perm.cpp:134:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  134 |    if(i+1==ret.size())
      |       ~~~^~~~~~~~~~~~
/usr/bin/ld: /tmp/ccTZAM6r.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccNZ5Lwu.o:perm.cpp:(.text.startup+0x20): first defined here
collect2: error: ld returned 1 exit status