Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>




using namespace std;




typedef unsigned short us;




int N;
int M;








int toInt(char ch){
&#160; &#160; if(ch>='0'&&ch<='9')return ch-'0';
&#160; &#160; return ch-'A'+10;
}
int toChar(int num){
&#160; &#160; if(num>=0&&num<=9)return num+'0';
&#160; &#160; return num-10+'A';
}




us toHex(string s){
&#160; &#160; us num=0;
&#160; &#160; for(int j=0;j<=1;j++){
&#160; &#160; &#160; &#160; num+=toInt(s[j]);
&#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
&#160; &#160; }
&#160; &#160; return num;
}
vector<us> toHexList(string s){
&#160; &#160; vector<us> vus;
&#160; &#160; for(int i=0;i<s.size();i+=2){
&#160; &#160; &#160; &#160; string ss=s.substr(i,2);
&#160; &#160; &#160; &#160; us num=toHex(ss);
&#160; &#160; &#160; &#160; vus.push_back(num);
&#160; &#160; }
&#160; &#160; return vus;
}




string toStr(us num){
&#160; &#160; us a=num&(0x0F);
&#160; &#160; us b=(num&(0xF0))>>4;
&#160; &#160; string s;
&#160; &#160; s+=toChar(b);
&#160; &#160; s+=toChar(a);
&#160; &#160; return s;
}




vector<us> dePos2(vector<us> vus){
&#160; &#160; if(vus.size()==1)return vus;
&#160; &#160; int sz=vus.size();
&#160; &#160; for(int i=2;i<=sz;i++){
&#160; &#160; &#160; &#160; if(sz%i!=0)continue;
&#160; &#160; &#160; &#160; bool isDecom=true;
&#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
&#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
&#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; if(isDecom){
&#160; &#160; &#160; &#160; &#160; &#160; vector<us> res;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; res.push_back(vus[j]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; return res;
&#160; &#160; &#160; &#160; }
&#160; &#160; }
&#160; &#160; return vus;
}




vector<us> dePos(vector<us> vus){
&#160; &#160; if(vus.size()==1)return vus;
&#160; &#160; int sz=vus.size();
&#160; &#160; for(int i=2;i<=sz;i++){
&#160; &#160; &#160; &#160; if(sz%i!=0)continue;
&#160; &#160; &#160; &#160; bool isDecom=true;
&#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
&#160; &#160; &#160; &#160; &#160; &#160; if(vus[j]!=vus[j%(sz/i)]){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; //if(j%(sz/i)==0)continue;
&#160; &#160; &#160; &#160; &#160; &#160; //else if(vus[j]!=vus[(j/(sz/i))+j%(sz/i)]){
&#160; &#160; &#160; &#160; &#160; &#160; // &#160; &#160;isDecom=false;
&#160; &#160; &#160; &#160; &#160; &#160; // &#160; &#160;break;
&#160; &#160; &#160; &#160; &#160; &#160; //}
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; if(isDecom){
&#160; &#160; &#160; &#160; &#160; &#160; vector<us> res;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<sz/i;j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; res.push_back(vus[j]);
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; return res;
&#160; &#160; &#160; &#160; }
&#160; &#160; }
&#160; &#160; //for(int i=1;i<=sz;i++){
&#160; &#160; // &#160; &#160;if(sz%i!=0)continue;
&#160; &#160; // &#160; &#160;bool isDecom=true;
&#160; &#160; // &#160; &#160;for(int j=0;j<sz;j++){
&#160; &#160; // &#160; &#160; &#160; &#160;if(j%(sz/i)==0)continue;
&#160; &#160; // &#160; &#160; &#160; &#160;else if(vus[j]!=0){
&#160; &#160; // &#160; &#160; &#160; &#160; &#160; &#160;isDecom=false;
&#160; &#160; // &#160; &#160; &#160; &#160; &#160; &#160;break;
&#160; &#160; // &#160; &#160; &#160; &#160;}
&#160; &#160; // &#160; &#160;}
&#160; &#160; // &#160; &#160;if(isDecom){
&#160; &#160; // &#160; &#160; &#160; &#160;vector<us> res;
&#160; &#160; // &#160; &#160; &#160; &#160;for(int j=0;j<sz;j++){
&#160; &#160; // &#160; &#160; &#160; &#160; &#160; &#160;if(j%(sz/i)==0){
&#160; &#160; // &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;res.push_back(vus[j]);
&#160; &#160; // &#160; &#160; &#160; &#160; &#160; &#160;}
&#160; &#160; // &#160; &#160; &#160; &#160;}
&#160; &#160; // &#160; &#160; &#160; &#160;return res;
&#160; &#160; // &#160; &#160;}
&#160; &#160; //}
&#160; &#160; return vus;
}




vector<us> nums[10];




typedef long long ll;
ll gcd(ll a,ll b){
&#160; &#160; if(b==0)return a;
&#160; &#160; return gcd(b,a%b);
}
ll lcm(ll a,ll b){
&#160; &#160; return a*b/gcd(a,b);
}








int main(){
&#160; &#160; cin>>N;
&#160; &#160; while(N--){
&#160; &#160; &#160; &#160; cin>>M;
&#160; &#160; &#160; &#160; ll L=1;
&#160; &#160; &#160; &#160; bool con=false;
&#160; &#160; &#160; &#160; for(int i=0;i<M;i++){
&#160; &#160; &#160; &#160; &#160; &#160; string s;
&#160; &#160; &#160; &#160; &#160; &#160; cin>>s;
&#160; &#160; &#160; &#160; &#160; &#160; nums[i]=(toHexList(s));
&#160; &#160; &#160; &#160; &#160; &#160; bool match=true;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=1;j<nums[i].size();j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(nums[i][0]!=nums[i][j])match=false;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; if(match){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; vector<us> tmp;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; tmp.push_back(nums[i][0]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; nums[i]=tmp;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; else{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; nums[i]=dePos2(nums[i]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; //nums[i]=dePos2(nums[i]);
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; L=lcm(L,(ll)nums[i].size());
&#160; &#160; &#160; &#160; &#160; &#160; if(L>1024){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; cout<<"Too complex."<<endl;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; con=true;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; break;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; if(con)continue;
&#160; &#160; &#160; &#160; for(int i=0;i<M;i++){
&#160; &#160; &#160; &#160; &#160; &#160; if(nums[i].size()==L)continue;
&#160; &#160; &#160; &#160; &#160; &#160; else{
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; vector<us> nlis;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<L;j++){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if(j%(nums[i].size())==0){
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; nlis.push_back(nums[i][j/(nums[i].size())]);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; else nlis.push_back(0);
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; nums[i]=nlis;
&#160; &#160; &#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; vector<us> res;
&#160; &#160; &#160; &#160; for(int i=0;i<L;i++){
&#160; &#160; &#160; &#160; &#160; &#160; us num=0;
&#160; &#160; &#160; &#160; &#160; &#160; for(int j=0;j<M;j++)num|=nums[j][i];
&#160; &#160; &#160; &#160; &#160; &#160; res.push_back(num);
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; bool match=true;
&#160; &#160; &#160; &#160; for(int j=1;j<res.size();j++){
&#160; &#160; &#160; &#160; &#160; &#160; if(res[0]!=res[j])match=false;
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; if(match){
&#160; &#160; &#160; &#160; &#160; &#160; vector<us> tmp;
&#160; &#160; &#160; &#160; &#160; &#160; tmp.push_back(res[0]);
&#160; &#160; &#160; &#160; &#160; &#160; res=tmp;
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; else{
&#160; &#160; &#160; &#160; &#160; &#160; res=dePos(res);
&#160; &#160; &#160; &#160; &#160; &#160;// res=dePos2(res);
&#160; &#160; &#160; &#160; }
&#160; &#160; &#160; &#160; for(int i=0;i<res.size();i++)cout<<toStr(res[i]);
&#160; &#160; &#160; &#160; cout<<endl;
&#160; &#160; }




&#160; &#160; return 0;
}

Compiler output:
a.cc:31:2: error: stray '#' in program
   31 | &#160; &#160; if(ch>='0'&&ch<='9')return ch-'0';
      |  ^
a.cc:31:9: error: stray '#' in program
   31 | &#160; &#160; if(ch>='0'&&ch<='9')return ch-'0';
      |         ^
a.cc:32:2: error: stray '#' in program
   32 | &#160; &#160; return ch-'A'+10;
      |  ^
a.cc:32:9: error: stray '#' in program
   32 | &#160; &#160; return ch-'A'+10;
      |         ^
a.cc:35:2: error: stray '#' in program
   35 | &#160; &#160; if(num>=0&&num<=9)return num+'0';
      |  ^
a.cc:35:9: error: stray '#' in program
   35 | &#160; &#160; if(num>=0&&num<=9)return num+'0';
      |         ^
a.cc:36:2: error: stray '#' in program
   36 | &#160; &#160; return num-10+'A';
      |  ^
a.cc:36:9: error: stray '#' in program
   36 | &#160; &#160; return num-10+'A';
      |         ^
a.cc:43:2: error: stray '#' in program
   43 | &#160; &#160; us num=0;
      |  ^
a.cc:43:9: error: stray '#' in program
   43 | &#160; &#160; us num=0;
      |         ^
a.cc:44:2: error: stray '#' in program
   44 | &#160; &#160; for(int j=0;j<=1;j++){
      |  ^
a.cc:44:9: error: stray '#' in program
   44 | &#160; &#160; for(int j=0;j<=1;j++){
      |         ^
a.cc:45:2: error: stray '#' in program
   45 | &#160; &#160; &#160; &#160; num+=toInt(s[j]);
      |  ^
a.cc:45:9: error: stray '#' in program
   45 | &#160; &#160; &#160; &#160; num+=toInt(s[j]);
      |         ^
a.cc:45:16: error: stray '#' in program
   45 | &#160; &#160; &#160; &#160; num+=toInt(s[j]);
      |                ^
a.cc:45:23: error: stray '#' in program
   45 | &#160; &#160; &#160; &#160; num+=toInt(s[j]);
      |                       ^
a.cc:46:2: error: stray '#' in program
   46 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |  ^
a.cc:46:9: error: stray '#' in program
   46 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |         ^
a.cc:46:16: error: stray '#' in program
   46 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |                ^
a.cc:46:23: error: stray '#' in program
   46 | &#160; &#160; &#160; &#160; if(j==0)num=(num<<4);
      |                       ^
a.cc:47:2: error: stray '#' in program
   47 | &#160; &#160; }
      |  ^
a.cc:47:9: error: stray '#' in program
   47 | &#160; &#160; }
      |         ^
a.cc:48:2: error: stray '#' in program
   48 | &#160; &#160; return num;
      |  ^
a.cc:48:9: error: stray '#' in program
   48 | &#160; &#160; return num;
      |         ^
a.cc:51:2: error: stray '#' in program
   51 | &#160; &#160; vector<us> vus;
      |  ^
a.cc:51:9: error: stray '#' in program
   51 | &#160; &#160; vector<us> vus;
      |         ^
a.cc:52:2: error: stray '#' in program
   52 | &#160; &#160; for(int i=0;i<s.size();i+=2){
      |  ^
a.cc:52:9: error: stray '#' in program
   52 | &#160; &#160; for(int i=0;i<s.size();i+=2){
      |         ^
a.cc:53:2: error: stray '#' in program
   53 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |  ^
a.cc:53:9: error: stray '#' in program
   53 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |         ^
a.cc:53:16: error: stray '#' in program
   53 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |                ^
a.cc:53:23: error: stray '#' in program
   53 | &#160; &#160; &#160; &#160; string ss=s.substr(i,2);
      |                       ^
a.cc:54:2: error: stray '#' in program
   54 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |  ^
a.cc:54:9: error: stray '#' in program
   54 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |         ^
a.cc:54:16: error: stray '#' in program
   54 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |                ^
a.cc:54:23: error: stray '#' in program
   54 | &#160; &#160; &#160; &#160; us num=toHex(ss);
      |                       ^
a.cc:55:2: error: stray '#' in program
   55 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |  ^
a.cc:55:9: error: stray '#' in program
   55 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |         ^
a.cc:55:16: error: stray '#' in program
   55 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |                ^
a.cc:55:23: error: stray '#' in program
   55 | &#160; &#160; &#160; &#160; vus.push_back(num);
      |                       ^
a.cc:56:2: error: stray '#' in program
   56 | &#160; &#160; }
      |  ^
a.cc:56:9: error: stray '#' in program
   56 | &#160; &#160; }
      |         ^
a.cc:57:2: error: stray '#' in program
   57 | &#160; &#160; return vus;
      |  ^
a.cc:57:9: error: stray '#' in program
   57 | &#160; &#160; return vus;
      |         ^
a.cc:64:2: error: stray '#' in program
   64 | &#160; &#160; us a=num&(0x0F);
      |  ^
a.cc:64:9: error: stray '#' in program
   64 | &#160; &#160; us a=num&(0x0F);
      |         ^
a.cc:65:2: error: stray '#' in program
   65 | &#160; &#160; us b=(num&(0xF0))>>4;
      |  ^
a.cc:65:9: error: stray '#' in program
   65 | &#160; &#160; us b=(num&(0xF0))>>4;
      |         ^
a.cc:66:2: error: stray '#' in program
   66 | &#160; &#160; string s;
      |  ^
a.cc:66:9: error: stray '#' in program
   66 | &#160; &#160; string s;
      |         ^
a.cc:67:2: error: stray '#' in program
   67 | &#160; &#160; s+=toChar(b);
      |  ^
a.cc:67:9: error: stray '#' in program
   67 | &#160; &#160; s+=toChar(b);
      |         ^
a.cc:68:2: error: stray '#' in program
   68 | &#160; &#160; s+=toChar(a);
      |  ^
a.cc:68:9: error: stray '#' in program
   68 | &#160; &#160; s+=toChar(a);
      |         ^
a.cc:69:2: error: stray '#' in program
   69 | &#160; &#160; return s;
      |  ^
a.cc:69:9: error: stray '#' in program
   69 | &#160; &#160; return s;
      |         ^
a.cc:76:2: error: stray '#' in program
   76 | &#160; &#160; if(vus.size()==1)return vus;
      |  ^
a.cc:76:9: error: stray '#' in program
   76 | &#160; &#160; if(vus.size()==1)return vus;
      |         ^
a.cc:77:2: error: stray '#' in program
   77 | &#160; &#160; int sz=vus.size();
      |  ^
a.cc:77:9: error: stray '#' in program
   77 | &#160; &#160; int sz=vus.size();
      |         ^
a.cc:78:2: error: stray '#' in program
   78 | &#160; &#160; for(int i=2;i<=sz;i++){
      |  ^
a.cc:78:9: error: stray '#' in program
   78 | &#160; &#160; for(int i=2;i<=sz;i++){
      |         ^
a.cc:79:2: error: stray '#' in program
   79 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |  ^
a.cc:79:9: error: stray '#' in program
   79 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |         ^
a.cc:79:16: error: stray '#' in program
   79 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |                ^
a.cc:79:23: error: stray '#' in program
   79 | &#160; &#160; &#160; &#160; if(sz%i!=0)continue;
      |                       ^
a.cc:80:2: error: stray '#' in program
   80 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |  ^
a.cc:80:9: error: stray '#' in program
   80 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |         ^
a.cc:80:16: error: stray '#' in program
   80 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |                ^
a.cc:80:23: error: stray '#' in program
   80 | &#160; &#160; &#160; &#160; bool isDecom=true;
      |                       ^
a.cc:81:2: error: stray '#' in program
   81 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |  ^
a.cc:81:9: error: stray '#' in program
   81 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |         ^
a.cc:81:16: error: stray '#' in program
   81 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |                ^
a.cc:81:23: error: stray '#' in program
   81 | &#160; &#160; &#160; &#160; for(int j=0;j<sz;j++){
      |                       ^
a.cc:82:2: error: stray '#' in program
   82 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |  ^
a.cc:82:9: error: stray '#' in program
   82 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |         ^
a.cc:82:16: error: stray '#' in program
   82 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                ^
a.cc:82:23: error: stray '#' in program
   82 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                       ^
a.cc:82:30: error: stray '#' in program
   82 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                              ^
a.cc:82:37: error: stray '#' in program
   82 | &#160; &#160; &#160; &#160; &#160; &#160; if(j%(sz/i)==0)continue;
      |                                     ^
a.cc:83:2: error: stray '#' in program
   83 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |  ^
a.cc:83:9: error: stray '#' in program
   83 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |         ^
a.cc:83:16: error: stray '#' in program
   83 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                ^
a.cc:83:23: error: stray '#' in program
   83 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                       ^
a.cc:83:30: error: stray '#' in program
   83 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                              ^
a.cc:83:37: error: stray '#' in program
   83 | &#160; &#160; &#160; &#160; &#160; &#160; else if(vus[j]!=0){
      |                                     ^
a.cc:84:2: error: stray '#' in program
   84 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |  ^
a.cc:84:9: error: stray '#' in program
   84 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |         ^
a.cc:84:16: error: stray '#' in program
   84 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |                ^
a.cc:84:23: error: stray '#' in program
   84 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |                       ^
a.cc:84:30: error: stray '#' in program
   84 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |                              ^
a.cc:84:37: error: stray '#' in program
   84 | &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; isDecom=false;
      |