CSES - HIIT Open 2016 - Results
Submission details
Task:Interesting number
Sender:Barely Div 1
Submission time:2016-05-28 15:25:28 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1--details
#20.13 sdetails

Compiler report

input/code.cpp: In function 'void printmat(std::vector<std::vector<int> >)':
input/code.cpp:38:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < M.size(); i++){
                               ^
input/code.cpp:39:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int j = 0; j < M.size(); j++){
                                 ^

Code

#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <utility>

using namespace std;

typedef int32_t LL;
/*
vector<LL> matmul(vector<vector<LL> > M, vector<LL> v){
  int n = v.size();
  vector<LL> ans(n);
  for(int i = 0; i < n; i++){
    LL x = 0;
    for(int j = 0; j < n; j++){
      x += M[i][j] * v[j];
    }
    ans[i] = x % 64;
  }
  return ans;
}*/

void matmul2(vector<LL> & ans, vector<vector<LL> > M, vector<LL> v){
  int n = v.size();
  //vector<LL> ans(n);
  for(int i = 0; i < n; i++){
    LL x = 0;
    for(int j = 0; j < n; j++){
      x += M[i][j] * v[j];
    }
    ans[i] = x % 64;
  }
  //return ans;
}

void printmat(vector<vector<LL> > M){
    for(int i = 0; i < M.size(); i++){
      for(int j = 0; j < M.size(); j++){
	cout << M[i][j] << " ";
      }
      cout << endl;
    }
}

void read_matrix(vector< vector<LL> > & M, LL n){
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    for(int j = 0; j < n; j++){
      LL x = 0;
      if(s[j] >= 'A' && s[j] <= 'Z') x = s[j] - 'A';
      if(s[j] >= 'a' && s[j] <= 'z') x = s[j] - 'a' + 26;
      if(s[j] >= '0' && s[j] <= '9') x = s[j] - '0' + 52;
      if(s[j] == '+') x = 62;
      if(s[j] == '/') x = 63;
      M[i][j] = x;
    }
  }  //return M;
}

void solve(){
  LL n; cin >> n;
  vector<vector<LL> > A(n, vector<LL>(n));
  vector<vector<LL> > X(n, vector<LL>(n));
  read_matrix(A, n);
  read_matrix(X, n);
  vector<vector<LL> > A_T(n, vector<LL>(n)); // transpose
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      A_T[i][j] = A[j][i];
    }
  }  
  //printmat(A); printmat(A_T); printmat(X);
  
  for(int test = 0; test < 100; test++){
    vector<LL> v;
    for(int i = 0; i < n; i++){
      v.push_back(rand() % 64);
    }
    
    vector<LL> Xv(n), t(n), AA_Tv(n);
    
    matmul2(Xv, X,v);
    matmul2(t, A_T,v);
    matmul2(AA_Tv, A, t);
    
    //vector<LL> Xv(n); // DEBUG
    //vector<LL> AA_Tv(n); // DEBUG
    
    bool good = true;
    
    for(int i = 0; i < n; i++){
      if(Xv[i] != AA_Tv[i]) good = false;
    }
    
    if(!good){
      cout << 0 << "\n";
      return;
    }
  }
  
  cout << 1 << "\n";
}

int main(){
  srand(345348345);
  LL t; cin >> t;
  while(t--) solve();
}

Test details

Test 1

Verdict:

input
1000
9
300 988 956 931 116 3 386 202 ...

correct output
3
3
181
919
191
...

user output
(empty)

Test 2

Verdict:

input
1
100000
72 247 605 249 10 422 594 490 ...

correct output
191

user output
(empty)