鳶一折纸
2024-11-19 07:36:57
不妨将举行第
不难发现,第
将第
从第
最终我们可以用
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m, tot;
int a[N], b[N], ans[N];
vector<vector<int>> sq;
string s;
signed main()
{
ios::sync_with_stdio(0);
cin >> n >> m;
sq.resize(n + 1);
for (int i = 1; i <= n; ++i)
{
cin >> s, sq[i].resize(m + 1), a[i] = i;
for (int j = 1; j <= m; ++j)
sq[i][j] = s[j - 1] - '0';
}
for (int i = m; i >= 1; --i)
{
tot = 0;
for (int j = 1; j <= n; ++j)
if (sq[a[j]][i])
b[++tot] = a[j];
for (int j = 1; j <= n; ++j)
if (!sq[a[j]][i])
b[++tot] = a[j];
for (int j = 1; j <= n; ++j)
a[j] = b[j];
}
ans[1] = a[1];
for (int i = m; i >= 2; --i)
{
tot = 0;
for (int j = 1; j <= n; ++j)
if (sq[a[j]][i])
b[++tot] = a[j];
for (int j = 1; j <= n; ++j)
if (!sq[a[j]][i])
b[++tot] = a[j];
for (int j = 1; j <= n; ++j)
a[j] = b[j];
ans[i] = a[1];
}
for (int i = 1; i <= m; ++i)
cout << ans[i] << " ";
return 0;
}