D 参考代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
string s[N];
void solve(){map<string, int> mp;int n;cin >> n; for(int i = 1; i <= n; i ++){cin >> s[i];mp[s[i]] ++;}for(int i = 1; i <= n; i ++){ int ok = 0; for(int j = 0; j < s[i].size() - 1; j ++){ string s1, s2;for(int k = 0; k <= j; k ++){s1 += s[i][k];}for(int k = j + 1; k < s[i].size(); k ++){s2 += s[i][k];}if(mp[s1] && mp[s2]){ok = 1;break;}}cout << ok;}cout << endl;
}
int main(){int t;cin >> t;while(t --){solve();}return 0;
}
E 参考代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N][N];
void solve(){int n;cin >> n;for(int i = 1; i <= n; i ++){string s;cin >> s;for(int j = 1; j <= n; j ++){ a[i][j] = s[j - 1] - '0';}} int cnt = 0; for(int i = 1; i <= n / 2; i ++){for(int j = 1; j <= (n + 1) / 2; j ++){int res = a[i][j] + a[j][n + 1 - i] + a[n + 1 - i][n + 1 - j] + a[n + 1 - j][i];cnt += min(res, 4 - res);}}cout << cnt << endl;
}
int main(){int t;cin >> t;while(t --){solve();}return 0;
}