이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//struct Edge {int u, v, weight;bool operator<(Edge const& other) {return weight < other.weight;}};
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define sp ' '
#define pb push_back
#define ar for(int i=1;i<=n;i++)
using namespace std;
ll t=1;
const ll N=3e5+100;
ll n,m,q,k;
ll a[N],b[N],c[N];
vector<int>v[10000];
vector<int>ans;
bool ok(int l,int r)
{
if((r-l+1)%k!=0){return false;}
for(int i=0;i<n;i++){v[i].clear();}
ll lenth=(r-l+1)/k;
for(int i=0;i<k;i++)
{
for(int j=1;j<=lenth;j++)
{
ll ndx=(i)*lenth;ndx+=l-1;
v[i].push_back(a[ndx+j]);
}
}
// if(l==1&&r==4)for(int i=0;i<5;i++){for(auto j:v[i]){cout<<j<<" ";}cout<<endl;}
for(int i=0;i<lenth;i++)
{
set<int>s;
for(int j=0;j<k;j++)
{
s.insert(v[j][i]);
}
if(s.size()!=1){return false;}
}
ans=v[0];
return true;
}
void solve()
{
cin>>n>>k;
for(int i=1;i<=n;i++){cin>>a[i];}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(!ok(i,j)){continue;}
cout<<(j-i+1)/k<<endl;
for(auto i:ans){cout<<i<<" ";}cout<<endl;return;
}
}
cout<<-1<<endl;return;
}
int main()
{
//freopen("shell.in", "r", stdin);
// freopen("shell.out", "w", stdout);
ios::sync_with_stdio(NULL);
cin.tie(NULL);cout.tie(NULL);
// cin>>t;
while(t--){solve();}
return 0;
}
//09:00 :: 9:45
//10:30 ::
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |