Problem:
Scheduling Two Meetings
You are the chief judge of the International Collegiate Quiz Contest (ICQC) this year. You want to hold judge meetings twice for preparing the problem set of the contest. You proposed candidate schedules for the meetings, and all the judges answered for each of the time slots whether they would attend the meeting on-site or remotely via a video conference tool.
You have to choose a pair of two distinct time slots, so that every judge attends at least one of the two meetings on-site. When there are multiple such pairs, you’d like to choose one with the largest number of judges attending both meetings on-site. If multiple pairs are still equally desirable with these criteria, one with the earlier first meeting is preferred. If there still remain multiple pairs with the same time slot for the first meeting, the one with the earliest second meeting should be chosen.
Input
The input consists of a single test case of the following format.
$n$ $m$
$a_{1,1}$ ... $a_{1,m}$
$\vdots$
$a_{n,1}$ ... $a_{n,m}$
Two integers $n$ and $m$ are given in the first line. The first integer $n$ ($2 \leq n \leq 2 \times 10^5$) is the number of candidate time slots. Here, the candidate time slots are numbered 1 through $n$, and smaller numbers mean earlier time slots. The second integer $m$ ($2 \leq m \leq 20$) is the number of judges.
In the following $n$ lines, $a_{i,j}$ is either a character
Y
indicating that the $j$-th judge attends a meeting at the $i$-th candidate time slot on-site, or a character
N
indicating remote attendance.
Output
Output a line containing the two time slot numbers of the most preferable choice, separated by a space, with the earlier time slot first. If there are no pairs of time slots satisfying the condition, output
No
.
Sample Input 1
4 3
NNY
YYN
YNY
NYY
Sample Output 1
2 3
Sample Input 2
3 6
NNNYYY
YYNYYN
YYYNNN
Sample Output 2
1 3
Sample Input 3
6 5
NNNNN
YNNNY
YYNNN
YYNNN
NYYNY
NNYYY
Sample Output 3
3 6
Sample Input 4
3 3
YNN
NYN
NNY
Sample Output 4
No
Sample Input 5
4 4
NYNN
YNYY
YNYN
NNYY
Sample Output 5
1 2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#include <numeric>
using namespace std;

using i64 = int64_t;

#define rep(i, n) for(i64 i = 0; i < (n); i++)
#define each(x, a) for(auto& x: a)

template<class T, T id, T (*op)(T,T)>
struct SegTree{
	i64 n=1;
	vector<T> k;
	public:
	void update(int i, T x) {
		i += n;
		k[i] = op(k[i], x);
		while(1<i){
			i/=2;
			k[i] = op(k[i*2], k[i*2+1]);
		}

	};
	T query(i64 l, i64 r) {
		T x = id;
		l+=n;
		r+=n;
		while(l<r) {
		    if (l&1) x=op(x,k[l++]);
		    if (r&1) x=op(x,k[--r]);
		    l>>=1;
		    r>>=1;
		}

		return x;
	};
	SegTree(std::vector<T> a) {
		int m = a.size();
		while(n<=m+1)n*=2;
		this->k=vector<T>(n*2, id);
		rep(i,m) k[n+i]=a[i];
		for(i64 i=n-1;0<i;i--) k[i] = op(k[i*2], k[i*2+1]);
	}
};

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T> &v) {
	os << "[";
	for (i64 i = 0; i << v.size(); ++i) {
		if (i == 0) {
			os << ", ";
		}
		os << v[i];
	}
	os << "]";
	return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::unordered_set<T> &v) {
	os << "{";
	for (i64 i = 0; i << v.size(); ++i) {
		if (i == 0) {
			os << ", ";
		}
		os << v[i];
	}
	os << "}";
	return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T> &v) {
	os << "{";
	for (i64 i = 0; i << v.size(); ++i) {
		if (i == 0) {
			os << ", ";
		}
		os << v[i];
	}
	os << "}";
	return os;
}
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::pair<T, T> &v) {
	os << "(";
	os << v.first;
	os << ", ";
	os << v.second;
	os << ")";
	return os;
}

#define dbg(x) ([&]() { auto _dbg_x = (x); cerr << "[dbg L" << __LINE__ << "] " << #x << " = "; cerr << _dbg_x << endl; return _dbg_x; }())

using ll=long long;
void chmin(int& x,int y) {if(x>y) x=y;}
using pii=pair<int,int>;

int main(){
	int n,m;
	cin >> n >> m;
	int f=(1<<m)-1,count=0;

	int inf=1234567890;
	vector<int> in(n);
	vector<vector<int>> a((1<<m),vector<int>(m+1,inf));
	rep(i,n){
		string s;
		cin >> s;
		rep(j,m) {
			in[i] *= 2;
			if (s[j] == 'Y') in[i]++;
		}
		if(in[i]==f) count++;
		chmin(a[in[i]][0],i);
	}

	if(count){
		vector<pii> p(n);
		rep(i,n) p[i]=pii(__popcount(f^in[i]),i);
		sort(p.begin(),p.end());
		int x=p[0].second+1,y=p[1].second+1;
		if(x>y) swap(x,y);
		cout << x << " " << y << endl;
		return 0;
	}

	for(int i=(1<<m)-1;0<=i;i--) rep(l,m) rep(j,m) if((i>>j)&1){
		chmin(a[i^(1<<j)][l+1],a[i][l]);
	}

	pii ans=pii(inf,inf);
	int nowmax=0;
	rep(i,n){
		rep(j,m+1) if(a[f^in[i]][j]<inf){
			int x=i,y=a[f^in[i]][j];
			if(x>y) swap(x,y);
			if(nowmax<=j){
				if(nowmax<j||x<ans.first||(x==ans.first&&y<ans.second)) ans=pii(x,y);
				nowmax=j;
			}
		}
	}

	if(ans==pii(inf,inf)) cout << "No" << endl;
	else cout << ans.first+1 << " " << ans.second+1 << endl;

}
accuracy: 1
time_ms: 720
memory_kb: 126960
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;

int main()
{
    unordered_map<ll, ll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    ll mx = 0;
    pll ans = {INF, INF};
    vvll cnts(M + 1);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        ll cnt = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y')
            {
                val++;
                cnt++;
            }
        }
        // S[i] = val;
        // cout << val << endl;
        if(!mns.count(val))
        {
            mns[val] = i;
            cnts[cnt].emplace_back(val);
            // cnts[M - cnt].emplace_back(((1LL << M) - 1) ^ val);
        }
        else if(val == ((1LL << M) - 1))
        {
            if(chmax(mx, 2*M))
            {
                // cout << mns[val] << " " << i << endl;
                ans = {mns[val], i};
            }
        }
    }
    if(mx == 2*M)
    {
        // cout << "test" << endl;
        cout << ans.first + 1 << " " << ans.second + 1 << endl;
        return 0;
    }
    // for(auto &vec : cnts)
    // {
    //     sort(all(vec));
    //     vec.erase(unique(all(vec)), vec.end());
    // }
    unordered_map<ll, pll> mxs;
    ll B = M/2;
    for(ll cnt = M; cnt >= B; cnt--)
    {
        sort(all(cnts[cnt]));
        cnts[cnt].erase(unique(all(cnts[cnt])), cnts[cnt].end());
        for(auto val : cnts[cnt])
        {
            if(mns.count(val))
            {
                if(!mxs.count(val)) mxs[val] = {cnt, mns[val]};
            }
            // if(!mxs.count(val)) continue;
            auto [c, id] = mxs[val];
            rep(i, M)
            {
                if((val >> i) & 1)
                {
                    ll nval = val ^ (1LL << i);
                    if(mxs.count(nval))
                    {
                        if(mxs[nval].first < c || (mxs[nval].first == c && mxs[nval].second > id)) mxs[nval] = {c, id};
                    }
                    else
                    {
                        mxs[nval] = {c, id};
                        cnts[cnt - 1].emplace_back(nval);
                    }
                }
            }
        }
    }
    unordered_map<ll, pll> memo;
    function<pll(ll)> dfs = [&](ll val)->pll
    {
        ll cnt = __popcount((ull)val);
        if(cnt >= B - 1)
        {
            if(mxs.count(val)) return mxs[val];
            else return {-1, INF};
        }
        if(memo.count(val)) return memo[val];
        pll ret = {-1, INF};
        if(mns.count(val))
        {
            ret = {cnt, mns[val]};
        }
        rep(i, M)
        {
            if(!((val >> i) & 1))
            {
                ll nval = val | (1LL << i);
                auto [c, id] = dfs(nval);
                if(ret.first < c || (ret.first == c || ret.second > id)) ret = {c, id};
            }
        }
        return memo[val] = ret;
    };
    for(auto [b1, i1] : mns)
    {
        ll cnt = __popcount((ull)b1);
        ll cov = ((1LL << M) - 1) ^ b1;
        auto [c, i2] = dfs(cov);
        if(i2 == INF || i1 == i2) continue;
        if(mx < cnt + c || (mx == cnt + c && ans > pll{minmax(i1, i2)}))
        {
            mx = cnt + c;
            ans = minmax(i1, i2);
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 1
time_ms: 450
memory_kb: 80880
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;
int main()
{
    unordered_map<ll, ll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    ll mx = 0;
    pll ans = {INF, INF};
    vvll cnts(M + 1);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        ll cnt = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y')
            {
                val++;
                cnt++;
            }
        }
        // S[i] = val;
        if(!mns.count(val))
        {
            mns[val] = i;
            cnts[cnt].emplace_back(val);
            // cnts[M - cnt].emplace_back(((1LL << M) - 1) ^ val);
        }
        else if(val == ((1LL << M) - 1))
        {
            if(chmax(mx, 2*M))
            {
                ans = {mns[val], i};
            }
        }
    }
    if(mx == 2*M)
    {
        cout << ans.first + 1 << " " << ans.second + 1 << endl;
        return 0;
    }
    for(auto &vec : cnts)
    {
        sort(all(vec));
        vec.erase(unique(all(vec)), vec.end());
    }
    unordered_map<ll, pll> mxs;
    ll B = M/2;
    for(ll cnt = M; cnt >= B; cnt--)
    {
        // sort(all(cnts[cnt]));
        // cnts[cnt].erase(unique(all(cnts[cnt])), cnts[cnt].end());
        for(auto val : cnts[cnt])
        {
            if(mns.count(val))
            {
                if(!mxs.count(val)) mxs[val] = {cnt, mns[val]};
            }
            if(!mxs.count(val)) continue;
            auto [c, id] = mxs[val];
            rep(i, M)
            {
                if((val >> i) & 1)
                {
                    ll nval = val ^ (1LL << i);
                    if(mxs.count(nval))
                    {
                        if(mxs[nval].first < c || (mxs[nval].first == c && mxs[nval].second > id)) mxs[nval] = {c, id};
                    }
                    else
                    {
                        mxs[nval] = {c, id};
                        cnts[cnt - 1].emplace_back(nval);
                    }
                }
            }
        }
    }
    unordered_map<ll, pll> memo;
    function<pll(ll)> dfs = [&](ll val)->pll
    {
        ll cnt = __popcount((ull)val);
        if(cnt >= B)
        {
            if(mxs.count(val)) return mxs[val];
            else return {-1, INF};
        }
        if(memo.count(val)) return memo[val];
        pll ret = {-1, INF};
        if(mns.count(val))
        {
            ret = {cnt, mns[val]};
        }
        rep(i, M)
        {
            if(!((val >> i) & 1))
            {
                ll nval = val | (1LL << i);
                auto [c, id] = dfs(nval);
                if(ret.first < c || (ret.first == c || ret.second > id)) ret = {c, id};
            }
        }
        return memo[val] = ret;
    };
    for(auto [b1, i1] : mns)
    {
        ll cnt = __popcount((ull)b1);
        ll cov = ((1LL << M) - 1) ^ b1;
        auto [c, i2] = dfs(cov);
        if(i2 == INF) continue;
        if(mx < cnt + c || (mx == cnt + c && ans > pll{minmax(i1, i2)}))
        {
            mx = cnt + c;
            ans = minmax(i1, i2);
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 10
memory_kb: 5376
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;
int main()
{
    unordered_map<ll, pll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y') val++;
        }
        // S[i] = val;
        if(!mns.count(val)) mns[val] = {i, INF};
        else if(mns[val].second == INF) mns[val].second = i;
    }
    // for(auto [key, val] : mns) cout << key << " " << val << endl;
    unordered_map<ll, pll> cov;
    ll B = M/2;
    for(auto [b1, pi1] : mns)
    {
        ll cnt = 0;
        vll bb;
        rep(i, M)
        {
            if((b1 >> i) & 1)
            {
                bb.emplace_back(i);
                cnt++;
            }
        }
        vll P(bb.size(), 0);
        for(ll k = 0; k <= min((ll)bb.size(), B); k++)
        {
            vll P(bb.size(), 0);
            rep(i, k) P[bb.size() - i - 1] = 1;
            do
            {
                ll num = 0;
                rep(i, P.size())
                {
                    if(!P[i]) continue;
                    num |= 1LL << bb[i];
                }
                if(!cov.count(num)) cov[num] = {cnt, pi1.first};
                else if(cov[num].first < cnt || (cov[num].first == cnt && cov[num].second > pi1.first))
                {
                    cov[num] = {cnt, pi1.first};
                }
            } while (next_permutation(all(P)));
        }
    }
    ll mx = 0;
    pll ans = {INF, INF};
    for(auto [b1, pi1] : mns)
    {
        ll i1 = pi1.first;
        ll base = 0;
        ll cnt = 0;
        rep(i, M)
        {
            if(!((b1 >> i) & 1)) base |= 1LL << i;
            else cnt++;
        }
        if(__popcount((ull)base) <= B)
        {
            if(!cov.count(base)) continue;
            auto [pls, i2] = cov[base];
            if(mx < cnt + pls || (mx == cnt + pls && ans > pll{minmax(i1, i2)}))
            {
                mx = cnt + pls;
                ans = minmax(i1, i2);
            }
            continue;
        }
        ll b2 = b1;
        if(mns.count(b2 | base))
        {
            ll i2 = mns[b2 | base].first;
            if(i1 == i2) i2 = mns[b2 | base].second;
            if(i2 != INF)
            {
                ll tmp = cnt + __popcount((ull)(b2 | base));
                if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
                {
                    mx = tmp;
                    ans = minmax(i1, i2);
                }
            }
        }
        while(b2 > 0)
        {
            // cout << b1 << " " << b2 << endl;
            b2 = (b2 - 1) & b1;
            if(!mns.count(b2 | base)) continue;
            ll i2 = mns[b2 | base].first;
            if(i1 == i2) i2 = mns[b2 | base].second;
            if(i2 == INF) continue;
            ll tmp = cnt + __popcount((ull)(b2 | base));
            if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
            {
                mx = tmp;
                ans = minmax(i1, i2);
            }
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 210
memory_kb: 4864
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;
int main()
{
    unordered_map<ll, pll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y') val++;
        }
        // S[i] = val;
        if(!mns.count(val)) mns[val] = {i, INF};
        else if(mns[val].second == INF) mns[val].second = i;
    }
    // for(auto [key, val] : mns) cout << key << " " << val << endl;
    unordered_map<ll, pll> cov;
    ll B = M/2;
    for(auto [b1, pi1] : mns)
    {
        ll cnt = 0;
        vll bb;
        rep(i, M)
        {
            if((b1 >> i) & 1)
            {
                bb.emplace_back(i);
                cnt++;
            }
        }
        vll P(bb.size(), 0);
        for(ll k = 0; k <= min((ll)bb.size(), B); k++)
        {
            vll P(bb.size(), 0);
            rep(i, k) P[bb.size() - i - 1] = 1;
            do
            {
                ll num = 0;
                rep(i, P.size())
                {
                    if(!P[i]) continue;
                    num |= 1LL << bb[i];
                }
                if(!cov.count(num)) cov[num] = {cnt, pi1.first};
                else chmin(cov[num], pll{cnt, pi1.first});
            } while (next_permutation(all(P)));
        }
    }
    ll mx = 0;
    pll ans = {INF, INF};
    for(auto [b1, pi1] : mns)
    {
        ll i1 = pi1.first;
        ll base = 0;
        ll cnt = 0;
        rep(i, M)
        {
            if(!((b1 >> i) & 1)) base |= 1LL << i;
            else cnt++;
        }
        if(__popcount((ull)base) <= B)
        {
            if(!cov.count(base)) continue;
            auto [pls, i2] = cov[base];
            if(mx < cnt + pls || (mx == cnt + pls && ans > pll{minmax(i1, i2)}))
            {
                mx = cnt + pls;
                ans = minmax(i1, i2);
            }
            continue;
        }
        ll b2 = b1;
        if(mns.count(b2 | base))
        {
            ll i2 = mns[b2 | base].first;
            if(i1 == i2) i2 = mns[b2 | base].second;
            if(i2 != INF)
            {
                ll tmp = cnt + __popcount((ull)(b2 | base));
                if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
                {
                    mx = tmp;
                    ans = minmax(i1, i2);
                }
            }
        }
        while(b2 > 0)
        {
            // cout << b1 << " " << b2 << endl;
            b2 = (b2 - 1) & b1;
            if(!mns.count(b2 | base)) continue;
            ll i2 = mns[b2 | base].first;
            if(i1 == i2) i2 = mns[b2 | base].second;
            if(i2 == INF) continue;
            ll tmp = cnt + __popcount((ull)(b2 | base));
            if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
            {
                mx = tmp;
                ans = minmax(i1, i2);
            }
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 200
memory_kb: 4864
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;
int main()
{
    unordered_map<ll, pll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y') val++;
        }
        // S[i] = val;
        if(!mns.count(val)) mns[val] = {i, INF};
        else if(mns[val].second == INF) mns[val].second = i;
    }
    // for(auto [key, val] : mns) cout << key << " " << val << endl;
    ll mx = 0;
    pll ans = {INF, INF};
    rep(b1, 1LL << M)
    {
        if(!mns.count(b1)) continue;
        ll i1 = mns[b1].first;
        ll base = 0;
        rep(i, M) if(!((b1 >> i) & 1)) base |= 1LL << i;
        ll b2 = b1;
        if(mns.count(b2 | base))
        {
            ll i2 = mns[b2 | base].first;
            if(i1 == i2) i2 == mns[b2 | base].second;
            if(i2 != INF)
            {
                ll tmp = __popcount((ull)b1) + __popcount((ull)(b2 | base));
                if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
                {
                    mx = tmp;
                    ans = minmax(i1, i2);
                }
            }
        }
        while(b2 > 0)
        {
            // cout << b1 << " " << b2 << endl;
            b2 = (b2 - 1) & b1;
            if(!mns.count(b2 | base)) continue;
            ll i2 = mns[b2 | base].first;
            if(i1 == i2) i2 = mns[b2 | base].second;
            if(i2 == INF) continue;
            ll tmp = __popcount((ull)b1) + __popcount((ull)(b2 | base));
            if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
            {
                mx = tmp;
                ans = minmax(i1, i2);
            }
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 20
memory_kb: 4224
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;
int main()
{
    unordered_map<ll, ll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y') val++;
        }
        // S[i] = val;
        if(!mns.count(val)) mns[val] = i;
    }
    // for(auto [key, val] : mns) cout << key << " " << val << endl;
    ll mx = 0;
    pll ans = {INF, INF};
    rep(b1, 1LL << M)
    {
        if(!mns.count(b1)) continue;
        ll i1 = mns[b1];
        ll base = 0;
        rep(i, M) if(!((b1 >> i) & 1)) base |= 1LL << i;
        ll b2 = b1;
        if(mns.count(b2 | base))
        {
            ll i2 = mns[b2 | base];
            if(i1 != i2)
            {
                ll tmp = __popcount((ull)b1) + __popcount((ull)(b2 | base));
                if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
                {
                    mx = tmp;
                    ans = minmax(i1, i2);
                }
            }
        }
        while(b2 > 0)
        {
            // cout << b1 << " " << b2 << endl;
            b2 = (b2 - 1) & b1;
            if(!mns.count(b2 | base)) continue;
            ll i2 = mns[b2 | base];
            if(i1 == i2) continue;
            ll tmp = __popcount((ull)b1) + __popcount((ull)(b2 | base));
            if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
            {
                mx = tmp;
                ans = minmax(i1, i2);
            }
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.28205128205128205
time_ms: 260
memory_kb: 6024
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define rep(i, a) for(ll i = 0; i < (a); i++)
#define all(a) begin(a), end(a)
#define sz(a) (a).size()
bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; }
template<class T> void out(T a) { cout << a << endl; }

using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ull = unsigned long long;
int main()
{
    unordered_map<ll, ll> mns;
    ll N, M; cin >> N >> M;
    // vll S(N);
    rep(i, N)
    {
        string s; cin >> s;
        ll val = 0;
        for(auto c : s)
        {
            val *= 2;
            if(c == 'Y') val++;
        }
        // S[i] = val;
        if(!mns.count(val)) mns[val] = i;
    }
    // for(auto [key, val] : mns) cout << key << " " << val << endl;
    ll mx = 0;
    pll ans = {INF, INF};
    rep(b1, 1LL << M)
    {
        if(!mns.count(b1)) continue;
        ll i1 = mns[b1];
        ll base = 0;
        rep(i, M) if(!((b1 >> i) & 1)) base |= 1LL << i;
        ll b2 = b1;
        if(mns.count(b2 | base))
        {
            ll i2 = mns[b2 | base];
            if(i1 != i1)
            {
                ll tmp = __popcount((ull)b1) + __popcount((ull)(b2 | base));
                if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
                {
                    mx = tmp;
                    ans = minmax(i1, i2);
                }
            }
        }
        while(b2 > 0)
        {
            // cout << b1 << " " << b2 << endl;
            b2 = (b2 - 1) & b1;
            if(!mns.count(b2 | base)) continue;
            ll i2 = mns[b2 | base];
            if(i1 == i2) continue;
            ll tmp = __popcount((ull)b1) + __popcount((ull)(b2 | base));
            if(mx < tmp || (mx == tmp && ans > pll{minmax(i1, i2)}))
            {
                mx = tmp;
                ans = minmax(i1, i2);
            }
        }
    }
    if(ans.first == INF) cout << "No" << endl;
    else cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.28205128205128205
time_ms: 250
memory_kb: 6024
final_rank: 11

code_snippet: #include <iostream>
#include <iomanip>//小数点出力用
//cout << fixed << setprecision(10) << ans;
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
using ll = long long;
using namespace std;
#define modPHash (ll)((1LL<<61)-1)
#define modP (ll)998244353
bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); }
int clk4(int num) { return (num - 2) * (num % 2); }
void yn(bool tf) { cout << (tf ? "YES\n" : "NO\n"); }

int pc(int x) {
    int res = 0;
    while (x) {
        if (x & 1) {
            res++;
        }
        x >>= 1;
    }
    return res;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    int M;
    cin >> M;
    string S[200002];
    int P[200002] = { 0 };
    vector<int>Full;
    pair<int,int> seg[1 << 20];
    for (int i = 0;i < (1 << 20);i++) {
        seg[i] = { -1,1e9 };
    }
    for (int i = 0;i < N;i++) {
        cin >> S[i];
        for (int j = 0;j < M;j++) {
            if (S[i][j] == 'Y')P[i] += (1 << j);
        }
        if (P[i] == (1 << M) - 1) {
            Full.push_back(i + 1);
        }
        if (seg[P[i]].first == -1) {
            seg[P[i]] = { pc(P[i]),i + 1};
        }
    }
    if (Full.size() >= 2) {
        cout << Full[0] << " " << Full[1] <<"\n";
        return 0;
    }
    for (int i = (1 << M) - 2;i >= 0;i--) {
        for (int j = 0;j < M;j++) {
            if ((i >> j) & 1)continue;
            int k = i + (1 << j);
            if (seg[i].first < seg[k].first) {
                seg[i] = seg[k];
            }
            else if (seg[i].first == seg[k].first && seg[i].second > seg[k].second) {
                seg[i] = seg[k];
            }
        }
    }
    int best = -1;
    int day1, day2;
    for (int i = 0;i < N;i++) {
        if (P[i] == (1 << M) - 1) continue;
        int R = (1 << M) - 1 - P[i];
        if (seg[R].first == -1) continue;
        int score = pc(P[i]) + seg[R].first;
        int d1 = min(seg[R].second, i + 1);
        int d2 = max(seg[R].second, i + 1);
        if (best < score) {
            best = score;
            day1 = d1;
            day2 = d2;            
        }
        else if (best == score && d1 < day1) {
            best = score;
            day1 = d1;
            day2 = d2;
        }
        else if (best == score && d1 == day1 && d2 < day2) {
            best = score;
            day1 = d1;
            day2 = d2;
        }
    }
    if (best == -1) {
        cout << "No\n";
    }
    else {
        cout << day1 << " " << day2 << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 28056
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> VLL;

#define rep(i, b) for(ll i=0; i<(b); ++i)
#define all(x) begin(x),end(x)

struct Data {
    ll one_count;
    ll index;
};

void chmax(Data &a, Data &b) {
    if (a.one_count < b.one_count) {
        a = b;
    } else if (a.one_count == b.one_count && a.index > b.index) {
        a = b;
    }
}

struct AnsData {
    ll one_count;
    ll index0, index1;

    AnsData(ll a, ll b, ll c) {
        one_count = a;
        index0 = min(b, c);
        index1 = max(b, c);
    }
};

void chmax(AnsData &a, AnsData &b) {
    if (a.one_count < b.one_count) {
        a = b;
    } else if (a.one_count == b.one_count) {
        if (a.index0 > b.index0) {
            a = b;
        } else if (a.index0 == b.index0 && a.index1 > b.index1) {
            a = b;
        }
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<bitset<20> > a(n, (1 << 20) - 1);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, m) {
            if (s[j] == 'N') a[i].set(j, 0);
        }
    }
    VLL y_count(n);
    rep(i, n) y_count[i] = a[i].count() - (20 - m);

    // coner
    {
        VLL cpy = y_count;
        sort(all(cpy));
        if (cpy[n - 1] == m && cpy[n - 2] != m) {
            ll all_i = find(all(y_count), m) - y_count.begin();
            AnsData ans(-1, -1, -1);
            rep(i, n) {
                if (i == all_i) continue;
                AnsData tmp(m + y_count[i], i, all_i);
                chmax(ans, tmp);
            }
            cout << ans.index0 + 1 << " " << ans.index1 + 1 << endl;
            return 0;
        }
    }

    vector<Data> dp(1 << 20, {-1, -1});

    rep(i, n) {
        Data tmp = {y_count[i], i};
        chmax(dp[a[i].to_ulong()], tmp);
    }

    rep(i, 20) {
        ll k = (1 << i);
        rep(j, 1<<19) {
            ll j0 = j / k;
            ll j1 = j % k;
            ll j2 = (j0 << (i + 1)) + j1;
            chmax(dp[j2], dp[j2 + k]);
        }
    }
    //cout << dp[0].one_count << " " << dp[0].index << endl;
    AnsData ans(-1, -1, -1);
    rep(i, n) {
        Data flip = dp[a[i].flip().to_ulong()];
        if (flip.one_count == -1) continue;
        if (flip.index == i) continue;
        AnsData tmp(flip.one_count + y_count[i], i, flip.index);
        chmax(ans, tmp);
    }
    if (ans.one_count == -1) cout << "No" << endl;
    else
        cout << ans.index0 + 1 << " " << ans.index1 + 1 << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 22512
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> VLL;

#define rep(i, b) for(ll i=0; i<(b); ++i)
#define all(x) begin(x),end(x)

struct Data {
    ll one_count;
    ll index;
};

void chmax(Data &a, Data &b) {
    if (a.one_count < b.one_count) {
        a = b;
    } else if (a.one_count == b.one_count && a.index > b.index) {
        a = b;
    }
}

struct AnsData {
    ll one_count;
    ll index0, index1;

    AnsData(ll a, ll b, ll c) {
        one_count = a;
        index0 = min(b, c);
        index1 = max(b, c);
    }
};

void chmax(AnsData &a, AnsData &b) {
    if (a.one_count < b.one_count) {
        a = b;
    } else if (a.one_count == b.one_count) {
        if (a.index0 > b.index0) {
            a = b;
        } else if (a.index0 == b.index0 && a.index1 > b.index1) {
            a = b;
        }
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<bitset<20> > a(n, (1 << 20) - 1);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, m) {
            if (s[j] == 'N') a[i].set(j, 0);
        }
    }
    VLL y_count(n);
    rep(i, n) y_count[i] = a[i].count() - (20 - m);

    // coner
    {
        VLL cpy = y_count;
        sort(all(cpy));
        if (cpy[n - 1] == m && cpy[n - 2] != m) {
            ll all_i = find(all(y_count), m) - y_count.begin();
            AnsData ans(-1, -1, -1);
            rep(i, n) {
                if (i == all_i) continue;
                AnsData tmp(m + y_count[i], i, all_i);
                chmax(ans, tmp);
            }
            cout << ans.index0 << " " << ans.index1 << endl;
            return 0;
        }
    }

    vector<Data> dp(1 << 20, {-1, -1});

    rep(i, n) {
        Data tmp = {y_count[i], i};
        chmax(dp[a[i].to_ulong()], tmp);
    }

    rep(i, 20) {
        ll k = (1 << i);
        rep(j, 1<<19) {
            ll j0 = j / k;
            ll j1 = j % k;
            ll j2 = (j0 << (i + 1)) + j1;
            chmax(dp[j2], dp[j2 + k]);
        }
    }
    //cout << dp[0].one_count << " " << dp[0].index << endl;
    AnsData ans(-1, -1, -1);
    rep(i, n) {
        Data flip = dp[a[i].flip().to_ulong()];
        if (flip.one_count == -1) continue;
        if (flip.index == i) continue;
        AnsData tmp(flip.one_count + y_count[i], i, flip.index);
        chmax(ans, tmp);
    }
    if (ans.one_count == -1) cout << "No" << endl;
    else
        cout << ans.index0 + 1 << " " << ans.index1 + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 70
memory_kb: 19448
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> VLL;

#define rep(i, b) for(ll i=0; i<(b); ++i)
#define all(x) begin(x),end(x)

struct Data {
    ll one_count;
    ll index;
};

void chmax(Data &a, Data &b) {
    if (a.one_count < b.one_count) {
        a = b;
    } else if (a.one_count == b.one_count && a.index > b.index) {
        a = b;
    }
}

struct AnsData {
    ll one_count;
    ll index0, index1;

    AnsData(ll a, ll b, ll c) {
        one_count = a;
        index0 = min(b, c);
        index1 = max(b, c);
    }
};

void chmax(AnsData &a, AnsData &b) {
    if (a.one_count < b.one_count) {
        a = b;
    } else if (a.one_count == b.one_count) {
        if (a.index0 > b.index0) {
            a = b;
        } else if (a.index0 == b.index0 && a.index1 > b.index1) {
            a = b;
        }
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<bitset<20> > a(n, (1 << 20) - 1);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, m) {
            if (s[j] == 'N') a[i].set(j, 0);
        }
    }
    VLL y_count(n);
    rep(i, n) y_count[i] = a[i].count() - (20 - m);

    vector<Data> dp(1 << 20, {-1, -1});

    rep(i, n) {
        dp[a[i].to_ulong()] = {y_count[i], i};
    }

    rep(i, 20) {
        ll k = (1 << i);
        rep(j, 1<<19) {
            ll j0 = j / k;
            ll j1 = j % k;
            ll j2 = (j0 << (i + 1)) + j1;
            chmax(dp[j2], dp[j2 + k]);
        }
    }

    AnsData ans(-1, -1, -1);
    rep(i, n) {
        Data flip = dp[a[i].flip().to_ulong()];
        if (flip.one_count == -1) continue;
        AnsData tmp(flip.one_count + y_count[i], i, flip.index);
        chmax(ans, tmp);
        //cout << ans.one_count << endl;
    }
    if (ans.one_count == -1) cout << "No" << endl;
    else
        cout << ans.index0 + 1 << " " << ans.index1 + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 80
memory_kb: 19660
final_rank: 18

code_snippet: #include<bits/stdc++.h>

using namespace std;

long long n, m;
set<long long> nums;
map<long long, long long> parent_map;
set<long long> bits;
map<long long , long long> bits_map;

void dfs(long long num, long long parent) {
    if (num == 0 || bits.count(num)) return;
    bits.insert(num);
    bits_map.insert({num, parent});
    for(int i = 0; i < m; i++){
        if((1 << i) & num) {
            dfs(num - (1 << i), parent);
        }
    }
}

int main(){
    cin >> n >> m;
    vector<string> a(n);
    for(auto &s:a){
        cin >> s;
    }
    vector<long long> temp;
    for(int i = n - 1; i >= 0; i--){
        long long b = 1, t = 0;
        for(auto c: a[i]){
            if(c == 'Y') {
                t += b;
            }
            b *= 2;
        }
        temp.push_back(t);
        nums.insert(t);
        parent_map[t] = i + 1;
    }
    reverse(temp.begin(), temp.end());
    if (nums.count((1 << m) - 1)) {
        long long all_y_index = -1;
        for(int i = 0; i < n; i++) {
            if (temp[i] == (1 << m) - 1) {
                all_y_index = i;
                break;
            }
        }
        long long max_popcount_index = -1;
        long long max_popcount = -1;
        for(int i = 0; i < n; i++) {
            if(i == all_y_index) continue;
            if(__builtin_popcount(temp[i]) > max_popcount) {
                max_popcount_index = i;
                max_popcount = __builtin_popcount(temp[i]);
            }
        }
        if (all_y_index > max_popcount_index) {
            swap(all_y_index, max_popcount_index);
        }
        cout << all_y_index + 1 << " " << max_popcount_index + 1 << endl;
        return 0;
    }

    // for(auto [f, s]: parent_map) {
    //     cout << f << " " << s << endl;
    // }
    for (int i = 0; i < n; i++) {
        dfs(temp[i], i + 1);
    }
    // for(auto [f, s]: bits_map) {
    //     cout << f << " " << s << endl;
    // }
    // cout << "aa" << endl;
    bits.insert(0);
    bits_map[0] = 1;

    set<pair<long long, long long>> anses;
    for (auto t: bits) {
        if (bits.count(((1LL << m) - 1) - t)) {
            long long e1 = bits_map[t];
            long long e2 = bits_map[((1LL << m) - 1) - t];
            if (e1 == e2) {
                e2 = 2;
            }
            if (e1 > e2) {
                swap(e1, e2);
            }
            e1--;
            e2--;
            anses.insert({e1, e2});
            // cout << e1 << " " << e2 << endl;
            // return 0;
        }
    }
    // for(auto [f, s] : anses) {
    //     cout << f << " " << s << endl;
    // }
    if (anses.empty()) {
        cout << "No" << endl;
        return 0;
    }
    long long max_both = __builtin_popcount(temp[(*anses.begin()).first] & temp[(*anses.begin()).second]);
    pair<long long, long long> ans = *anses.begin();
    for(auto [f, s]: anses) {
        // cout << ";" << __builtin_popcount(temp[f] & temp[s]) << endl;
        if (__builtin_popcount(temp[f] & temp[s]) > max_both) {
            max_both = __builtin_popcount(temp[f] & temp[s]);
            ans = {f, s};
        } 
        // else if (__builtin_popcount(temp[f] & temp[s]) == min_both) {
        //     ans = (ans < (pair<long long, long long>){f,s})? ans:(pair<long long, long long>){f,s};
        // }
    }
    cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.2564102564102564
time_ms: 120
memory_kb: 23116
final_rank: 13

code_snippet: #include<bits/stdc++.h>

using namespace std;

long long n, m;
set<long long> nums;
map<long long, long long> parent_map;
set<long long> bits;
map<long long , long long> bits_map;

void dfs(long long num, long long parent) {
    if (num == 0 || bits.count(num)) return;
    bits.insert(num);
    bits_map.insert({num, parent});
    for(int i = 0; i < m; i++){
        if((1 << i) & num) {
            dfs(num - (1 << i), parent);
        }
    }
}

int main(){
    cin >> n >> m;
    vector<string> a(n);
    for(auto &s:a){
        cin >> s;
    }
    vector<long long> temp;
    for(int i = 0; i < n; i++){
        long long b = 1, t = 0;
        for(auto c: a[i]){
            if(c == 'Y') {
                t += b;
            }
            b *= 2;
        }
        temp.push_back(t);
        nums.insert(t);
        parent_map[t] = i + 1;
    }
    // for(auto [f, s]: parent_map) {
    //     cout << f << " " << s << endl;
    // }
    for (int i = 0; i < n; i++) {
        dfs(temp[i], i + 1);
    }
    // for(auto [f, s]: bits_map) {
    //     cout << f << " " << s << endl;
    // }
    // cout << "aa" << endl;
    bits.insert(0);
    bits_map[0] = 1;

    set<pair<long long, long long>> anses;
    for (auto t: bits) {
        if (bits.count(((1LL << m) - 1) - t)) {
            long long e1 = bits_map[t];
            long long e2 = bits_map[((1LL << m) - 1) - t];
            if (e1 == e2) {
                e2 = 2;
            }
            if (e1 > e2) {
                swap(e1, e2);
            }
            e1--;
            e2--;
            anses.insert({e1, e2});
            // cout << e1 << " " << e2 << endl;
            // return 0;
        }
    }
    // for(auto [f, s] : anses) {
    //     cout << f << " " << s << endl;
    // }
    if (anses.empty()) {
        cout << "No" << endl;
        return 0;
    }
    long long max_both = __builtin_popcount(temp[(*anses.begin()).first] & temp[(*anses.begin()).second]);
    pair<long long, long long> ans = *anses.begin();
    for(auto [f, s]: anses) {
        // cout << ";" << __builtin_popcount(temp[f] & temp[s]) << endl;
        if (__builtin_popcount(temp[f] & temp[s]) > max_both) {
            max_both = __builtin_popcount(temp[f] & temp[s]);
            ans = {f, s};
        } 
        // else if (__builtin_popcount(temp[f] & temp[s]) == min_both) {
        //     ans = (ans < (pair<long long, long long>){f,s})? ans:(pair<long long, long long>){f,s};
        // }
    }
    cout << ans.first + 1 << " " << ans.second + 1 << endl;
}
accuracy: 0.1282051282051282
time_ms: 20
memory_kb: 7400
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int n,m;
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>m;
  vector<int>a(n);
  rep(i,n){
    string s;cin>>s;
    rep(j,m)a[i]=2*a[i]+(s[j]=='Y');
  }
  vector<int>f(1<<m,0);
  rep(i,n)f[a[i]]=popcount((unsigned int)a[i]);
  int whole=(1<<m)-1,mx=-1<<30,mxi=-1;
  auto it=ranges::find(a,whole);
  if(it!=a.end()){
    int i=distance(a.begin(),it);
    rep(j,n){
      if(i==j)continue;
      if(mx<f[a[j]])mx=f[a[j]],mxi=j;
    }
    cout<<1+min(i,mxi)<<' '<<1+max(i,mxi)<<endl;
    return 0;
  }
  rep(j,m)rep(i,1<<m)if((i&(1<<j))==0)f[i]=max(f[i],f[i|(1<<j)]);
  rep(i,n-1){
    if(a[i]==whole||a[i]==0)continue;
    int both=f[whole^a[i]]-popcount((unsigned int)(whole^a[i]));
    if(mx<both)mx=both,mxi=i;
  }
  if(mx<0){
    cout<<"No\n";
    return 0;
  }
  for(int j=mxi+1;j<n;++j){
    if((a[mxi]|a[j])==whole&&popcount((unsigned int)(a[mxi]&a[j]))==mx){
      cout<<1+mxi<<' '<<1+j<<endl;
      return 0;
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 8312
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int n,m,a[2<<17];
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>m;
  rep(i,n){
    string s;cin>>s;
    rep(j,m)a[i]=2*a[i]+(s[j]=='Y');
  }
  vector<int>f(1<<m,0);
  rep(i,n){
    f[a[i]]=__builtin_popcount((unsigned int)a[i]);
  }
  rep(j,m)rep(i,1<<m)if((i&(1<<j))==0)f[i]=max(f[i],f[i|(1<<j)]);

  int whole=((1<<m)-1);
  vector<int>whole_indices;
  rep(i,n){
    if(a[i]==whole)whole_indices.emplace_back(i);
  }
  if(2<=(int)whole_indices.size()){
    cout<<1+whole_indices[0]<<' '<<1+whole_indices[1]<<endl;
    return 0;
  }
  if(1==(int)whole_indices.size()){
    int mx=-1<<30,mxi=-1;
    rep(i,n){
      int pc=__builtin_popcount((unsigned int)a[i]);
      if(mx<pc&&pc!=m){
        mx=pc;
        mxi=i;
      }
    }
    cout<<1+min(mxi,whole_indices[0])<<' '<<1+max(mxi,whole_indices[0])<<endl;
    return 0;
  }

  int mx=-1<<30,mxi=-1;
  rep(i,n-1){
    if(a[i]==whole||a[i]==0)continue;
    int both=f[whole^a[i]]-__builtin_popcount((unsigned int)(whole^a[i]));
    if(mx<both){
      mx=both,mxi=i;
    }
  }

  if(mx<0){
    cout<<"No\n";
    return 0;
  }
  //cerr<<"Yes\n";
  for(int j=mxi+1;j<n;++j){
    if((a[mxi]|a[j])!=whole)continue;
    int pc=__builtin_popcount((unsigned int)(a[mxi]&a[j]));
    if(pc==mx){
      cout<<1+mxi<<' '<<1+j<<endl;
      return 0;
    }
  }
  assert(0);
}
accuracy: 1
time_ms: 20
memory_kb: 8312
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int n,m,a[2<<17];
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>m;
  rep(i,n){
    string s;cin>>s;
    rep(j,m)a[i]=2*a[i]+(s[j]=='Y');
  }
  vector<int>f(1<<m,0);
  rep(i,n){
    f[a[i]]=__builtin_popcount((unsigned int)a[i]);
  }
  rep(j,m)rep(i,1<<m)if((i&(1<<j))==0)f[i]=max(f[i],f[i|(1<<j)]);

  int whole=((1<<m)-1);
  vector<int>whole_indices;
  rep(i,n){
    if(a[i]==whole)whole_indices.emplace_back(i);
  }
  if(2<=(int)whole_indices.size()){
    cout<<1+whole_indices[0]<<' '<<1+whole_indices[1]<<endl;
    return 0;
  }
  if(1==(int)whole_indices.size()){
    int mx=-1<<30,mxi=-1;
    rep(i,n){
      int pc=__builtin_popcount((unsigned int)a[i]);
      if(mx<pc&&pc!=m){
        mx=pc;
        mxi=i;
      }
    }
    cout<<1+min(mxi,whole_indices[0])<<' '<<1+max(mxi,whole_indices[0])<<endl;
    return 0;
  }

  int mx=-1<<30,mxi=-1;
  rep(i,n-1){
    if(a[i]==whole||a[i]==0)continue;
    int both=f[whole^a[i]]-__builtin_popcount((unsigned int)(whole^a[i]));
    if(mx<both){
      mx=both,mxi=i;
    }
  }

  if(mx<0){
    cout<<"No\n";
    return 0;
  }
  //cerr<<"Yes\n";
  for(int j=mxi+1;j<n;++j){
    int pc=__builtin_popcount((unsigned int)(a[mxi]&a[j]));
    if(pc==mx){
      cout<<1+mxi<<' '<<1+j<<endl;
      return 0;
    }
  }
  assert(0);
}
accuracy: 0.358974358974359
time_ms: 20
memory_kb: 8308
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int n,m,a[2<<17];
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>m;
  rep(i,n){
    string s;cin>>s;
    rep(j,m)a[i]=2*a[i]+(s[j]=='Y');
  }
  vector<int>f(1<<m,0);
  rep(i,n){
    f[a[i]]=__builtin_popcount((unsigned int)a[i]);
  }
  rep(j,m)rep(i,1<<m)if((i&(1<<j))==0)f[i]=max(f[i],f[i|(1<<j)]);

  int whole=((1<<m)-1);
  vector<int>whole_indices;
  rep(i,n){
    if(a[i]==whole)whole_indices.emplace_back(i);
  }
  if(2<=(int)whole_indices.size()){
    cout<<1+whole_indices[0]<<' '<<1+whole_indices[1]<<endl;
    return 0;
  }
  if(1==(int)whole_indices.size()){
    int mx=-1<<30,mxi=-1;
    rep(i,n){
      int pc=__builtin_popcount((unsigned int)a[i]);
      if(mx<m+pc&&pc!=m){
        mx=m+pc;
        mxi=i;
      }
    }
    cout<<1+min(mxi,whole_indices[0])<<' '<<1+max(mxi,whole_indices[0])<<endl;
    return 0;
  }

  int mx=-1<<30,mxi=-1;
  rep(i,n-1){
    if(a[i]==whole)continue;
    int both=f[whole^a[i]]-__builtin_popcount((unsigned int)(whole^a[i]));
    if(mx<both){
      mx=both,mxi=i;
    }
  }

  if(mx<0){
    cout<<"No\n";
    return 0;
  }
  //cerr<<"Yes\n";
  for(int j=mxi+1;j<n;++j){
    int pc=__builtin_popcount((unsigned int)(a[mxi]&a[j]));
    if(pc==mx){
      cout<<1+mxi<<' '<<1+j<<endl;
      return 0;
    }
  }
  assert(0);
}
accuracy: 0.358974358974359
time_ms: 10
memory_kb: 8308
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int n,m,st[2<<17];
int f[1<<20];
int pc(int n){
  return popcount((uint32_t)n);
}
signed main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>n>>m;
  rep(i,n){
    string s;cin>>s;
    rep(j,m)if(s[j]=='Y')st[i]|=1<<j;
    f[st[i]]=pc(st[i]);
  }
  rep(i,m)rep(j,1<<m)if(!(j&(1<<i)))f[j]=max(f[j],f[j|(1<<i)]);
  int mx=-1,mxi=-1;
  {
    int cnt=0,pos=1<<30;
    rep(i,n){
      if(st[i]==(1<<m)-1)++cnt,pos=min(pos,i);
    }
    if(2<=cnt){
      mx=m,mxi=pos;
    }else if(cnt==1){
      rep(i,n){
        if(i==pos)continue;
        int val=pc(st[i]);
        if(mx<val){
          mx=val;
          mxi=min(pos,i);
        }
      }
    }
  }
  rep(i,n){
    int tgt=st[i]^((1<<m)-1);
    if(tgt){
      int val=f[tgt]-pc(tgt);
      if(mx<val){
        mx=val;
        mxi=i;
      }else if(mx==val){
        mxi=min(mxi,i);
      }
    }
  }
  //cerr<<"mx: "<<mx<<endl;
  //cerr<<"mxi: "<<mxi<<endl;
  if(mx<0){
    cout<<"No\n";
    return 0;
  }
  rep(i,n){
    if(i==mxi)continue;
    if(pc(st[i]&st[mxi])==mx&&pc(st[i]|st[mxi])==m){
      int l=min(i,mxi);
      int r=max(i,mxi);
      cout<<l+1<<' '<<r+1<<endl;
      return 0;
    }
  }
}
accuracy: 1
time_ms: 30
memory_kb: 8560
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> values(n);
    rep(i, n) {
        string s;
        cin >> s;
        int mask = 0;
        rep(j, m) if (s[j] == 'Y') mask |= (1 << j);
        values[i] = mask;
    }

    int FULL = (1 << m) - 1;

    // dp[mask] = best two (popcount, index)
    vector<pair<int, int>> dp1(1 << m, {-1, -1});
    vector<pair<int, int>> dp2(1 << m, {-1, -1});

    rep(i, n) {
        int val = values[i];
        int pop = __builtin_popcount(val);
        if (dp1[val].second == -1) {
            dp1[val] = {pop, i};
        } else if (dp2[val].second == -1 && i != dp1[val].second) {
            dp2[val] = {pop, i};
        }
    }

    // Bottom-up DP merge
    for (int mask = FULL; mask >= 1; --mask) {
        for (int j = 0; j < m; ++j) {
            if ((mask >> j) & 1) {
                int sub = mask ^ (1 << j);
                array<pair<int, int>, 4> cands = {
                    dp1[mask], dp2[mask], dp1[sub], dp2[sub]
                };

                sort(cands.begin(), cands.end(), [](auto a, auto b) {
                    if (a.first != b.first) return a.first > b.first;
                    return a.second < b.second;
                });

                // assign top 2 distinct indices
                dp1[sub] = {-1, -1};
                dp2[sub] = {-1, -1};
                for (auto [pop, idx] : cands) {
                    if (idx == -1) continue;
                    if (dp1[sub].second == -1) dp1[sub] = {pop, idx};
                    else if (dp2[sub].second == -1 && idx != dp1[sub].second) {
                        dp2[sub] = {pop, idx};
                        break;
                    }
                }
            }
        }
    }

    int best_pop = -1;
    pair<int, int> res = {-1, -1};

    rep(i, n) {
        int val = values[i];
        int need = FULL ^ val;
        auto [pop1, idx1] = dp1[need];
        int total = __builtin_popcount(val);

        int idx2 = -1;

        if (idx1 == -1) continue;
        if (idx1 == i) {
            tie(pop1, idx1) = dp2[need];
            if (idx1 == -1) continue;
        }

        total += pop1;

        int a = i, b = idx1;
        if (a > b) swap(a, b);

        if (total > best_pop) {
            best_pop = total;
            res = {a, b};
        } else if (total == best_pop) {
            if (a < res.first || (a == res.first && b < res.second)) {
                res = {a, b};
            }
        }
    }

    if (best_pop == -1) cout << "No\n";
    else cout << res.first + 1 << " " << res.second + 1 << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
accuracy: 1
time_ms: 180
memory_kb: 20480
final_rank: 5