Submission #201393

#TimeUsernameProblemLanguageResultExecution timeMemory
201393ShelbyDrvca (COCI19_drvca)C++11
0 / 110
47 ms3688 KiB
#include <bits/stdc++.h> #define MAXN 100005 using namespace std; int a[MAXN],n; bool f[MAXN]; bool check(int start,int d) { int now=a[start]; vector<int> v; f[start]=true; for(int i=start;i<n;i++) { if( (now+d)==a[i] ) { f[i]=true; now=a[i]; } } for(int i=0;i<n;i++) { if(f[i]==false) v.push_back(a[i]); } if(v.size()<=1) return true; else { int tmp=v[1]-v[0]; for(int i=1;i<v.size();i++) { if( (v[i]-v[i-1])!=tmp ) return false; } return true; } } void restart() { for(int i=0;i<n;i++) f[i]=false; } void ispisi() { vector<int> gr1; vector<int> gr2; for(int i=0;i<n;i++) { if(f[i]==true) gr2.push_back(a[i]); if(f[i]==false) gr1.push_back(a[i]); } printf("%d\n",gr1.size()); for(int i=0;i<gr1.size();i++) printf("%d ",gr1[i]); printf("\n"); printf("%d\n",gr2.size()); for(int i=0;i<gr2.size();i++) printf("%d ",gr2[i]); } int main() { int i,d; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); d=a[2]-a[1]; restart(); if(check(1,d)) ispisi(); else { restart(); d=a[2]-a[0]; if(check(0,d)) ispisi(); else { restart(); d=a[1]-a[0]; if(check(0,d)) ispisi(); else printf("-1\n"); } } return 0; }

Compilation message (stderr)

drvca.cpp: In function 'bool check(int, int)':
drvca.cpp:36:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=1;i<v.size();i++)
                     ~^~~~~~~~~
drvca.cpp: In function 'void ispisi()':
drvca.cpp:62:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",gr1.size());
                   ~~~~~~~~~~^
drvca.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr1.size();i++) printf("%d ",gr1[i]);
                 ~^~~~~~~~~~~
drvca.cpp:67:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",gr2.size());
                   ~~~~~~~~~~^
drvca.cpp:68:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr2.size();i++) printf("%d ",gr2[i]);
                 ~^~~~~~~~~~~
drvca.cpp: In function 'int main()':
drvca.cpp:73:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d",&n);
 ~~~~~^~~~~~~~~
drvca.cpp:74:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 for(i=0;i<n;i++) scanf("%d",&a[i]);
                  ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...