1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <algorithm>
#include <bitset>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) (int)(x).size()
#define CLEAR(tab) memset(tab, 0, sizeof(tab))
#define REP(x, n) for(int x = 0; x < (n); x++)
#define FOR(x, b, e) for(int x = (b); x <= (e); x++)
#define FORD(x, b, e) for(int x = (b); x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

typedef pair<int,int> PII;
typedef vector<int> VI;

const int MXN = 410;
const int C = 262144;
const int INF = 1000000001;
const int MOD = 1000000007;
const int UNKNOWN = -1;
const int MXL = 100001;

int n, L; 
vector<string> schedule;
vector<string> schedule3;
bitset<MXL> state[20];

template <std::size_t N>
struct BitsetHasher {
    std::size_t operator()(const std::bitset<N>& bs) const {
        std::size_t hash_value = 0;
        for (std::size_t i = 0; i < N; ++i) {
            if (bs[i]) {
                hash_value |= (1ULL << i);
            }
        }
        return hash_value;
    }
};

BitsetHasher<MXL> hasher;

bool check() {
    bitset<MXL> sum;
    FOR(i, 0, n - 1)
        sum = state[i] | sum;
    return sum.count() == L;
}

map<pair<long long, int> , int> DP;

pair<long long, int> calc_key(int k) {
    long long P = 0;
    FOR(i, 0, n - 1)
        P = P * 1000000007 + hasher(state[i]);
    return MP(P, k);
}

bool gen(int pos, int sleepTime) {
    if(pos == n) {
        return check();
    }

    pair<long long, int> p1 = calc_key(pos);
    if(DP.find(p1) != DP.end())
        return DP[p1];

    if(!check() ) {
        DP[p1] = 0;
        return 0;
    }

    bitset<MXL> q;
    FOR(i, 0, sleepTime - 1)
        q[i] = 1;
    
    FOR(i, 0, L - sleepTime) {
        if((q & state[pos]).count() == sleepTime) {
            state[pos] = state[pos] & (~q);
            if(gen(pos + 1, sleepTime)) {
                DP[p1] = 1;
                return 1;
            }
            state[pos] = state[pos] | q;
        }
        q[i] = 0;
        q[i + sleepTime] = 1;
    }
    DP[p1] = 0;
    return 0;
}

bool brut(int sleepTime) {
    DP.clear();
    FOR(i, 0, n - 1) {
        state[i].reset();
        FOR(j, 0, L - 1)
            state[i][j] = (schedule[i][j] == '.');
    }
    return gen(0, sleepTime);
}

int LL;

PII check2(int i) {
    int l = 0, r = L;
    int A = -1, B = 1;
    while(l <= r) {
        int s = (l + r) / 2;
        string schedule2;
        FOR(p, 0, n - 1) {
            schedule2.clear();
            FOR(k, 0, LL - 1)
                FOR(j, 0, i - 1)
                    schedule2 += schedule3[p][k];
            schedule[p] = schedule2;
        }
        if(brut(s)) {
            if((double)A / B < (double)s / i) {
                A = s;
                B = i;
            }
            l = s + 1;
        }
        else {
            r = s - 1;
        }
    }
    return MP(A, B);
}

void test(){
    cin>>n>>L;
    schedule.resize(n);
    schedule3.resize(n);
    FOR(i, 0, n - 1) {
        cin>>schedule[i];
        schedule3[i] = schedule[i];
    }

    FOR(i, 0, L - 1) {
        bool dec = 0;
        FOR(j, 0, n - 1) {
            if(schedule[j][i] == '.'){
                dec = 1;
                break;
            }
        }

        if(!dec){
            cout<<"-1\n";
            return;
        }
    }

    int A = -1, B = 1;
    LL = L;

    FOR(i, 1, n) {
        L = i * LL;
        PII p1 = check2(i);
        if((double)p1.F / p1.S > (double)A / B) {
            A = p1.F;
            B = p1.S;
        }
    }

    if(A < 0) {
        cout<<"-1\n";
        return;
    }
    int g = gcd(A, B);
    A /= g;
    B /= g;
    cout<<A<<"/"<<B<<"\n";
}

int main() {
    ios::sync_with_stdio(false);
    int te = 1;
    //cin>>te;
    while(te--)
        test();
    return 0;
}