Submission #474681

#TimeUsernameProblemLanguageResultExecution timeMemory
474681HossamHero7Sateliti (COCI20_satellti)C++14
50 / 110
3069 ms2660 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' void solve(){ int n,m; cin>>n>>m; vector <string> v(n); map <string,int> mp; for(auto &i:v) cin>>i; vector <string> ans; for(int i=0;i<n;i++){ int mn = 0; string ans=""; for(int shifJ=0;shifJ<=m*2;shifJ++){ string temp = v[i]; for(int j=0;j<m;j++){ temp[(j+shifJ)%m] = v[i][j]; } if(ans.size() == 0 || temp<ans){ ans = temp; mn = shifJ; } } mp[v[i]] = mn; } for(int shifI=0;shifI<=n*2;shifI++){ vector <string> v2; v2 = v; for(int i=0;i<n;i++){ v2[(i+shifI)%n] = v[i]; } int shifJ = mp[v2[0]]; for(int i=0;i<n;i++){ bool b = 0; for(int j=0;j<m;j++){ if(v2[i][j] != v2[i][0]) b = 1; } if(b) { shifJ = mp[v2[i]]; break; } } for(int i=0;i<n;i++){ string temp = v[i]; for(int j=0;j<m;j++){ temp[(j+shifJ)%m] = v2[i][j]; } v2[i] = temp; } if(ans.size() == 0 || v2<ans) ans = v2; } for(auto i : ans){ cout<<i<<endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...