Submission #14067015


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/












int N;
string S[505];
//---------------------------------------------------------------------------------------------------
string solve() {
	string pre = "";
	rep(i, 0, N / 2) {
		set<char> s1, s2;
		rep(x, 0, N) s1.insert(S[i][x]);
		rep(x, 0, N) s2.insert(S[N - 1 - i][x]);

		rep(_c, 0, 26) {
			char c('a' + _c);
			if (s1.count(c) && s2.count(c)) {
				pre += c;
				break;
			}
		}
	}

	if (pre.size() != N / 2) return "-1";

	string post = pre;
	reverse(all(post));

	if (N % 2 == 1) return pre + S[N / 2][0] + post;
	return pre + post;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> S[i];
	cout << solve() << endl;
}




Submission Info

Submission Time
Task F - Palindromic Matrix
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 7
Code Size 2044 Byte
Status AC
Exec Time 17 ms
Memory 3924 KB

Compile Error

./Main.cpp: In function ‘std::string solve()’:
./Main.cpp:52:17: warning: comparison of integer expressions of different signedness: ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
   52 |  if (pre.size() != N / 2) return "-1";
      |      ~~~~~~~~~~~^~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 7 / 7
Status
AC × 2
AC × 18
Set Name Test Cases
Sample sample1.txt, sample2.txt
All large0.txt, large1.txt, large2.txt, large3.txt, large4.txt, large5.txt, large_ng0.txt, large_ng1.txt, large_ng2.txt, sample1.txt, sample2.txt, small1.txt, small2.txt, small3.txt, small4.txt, small_ng2.txt, small_ng3.txt, small_ng4.txt
Case Name Status Exec Time Memory
large0.txt AC 13 ms 3840 KB
large1.txt AC 13 ms 3864 KB
large2.txt AC 13 ms 3744 KB
large3.txt AC 12 ms 3852 KB
large4.txt AC 17 ms 3924 KB
large5.txt AC 14 ms 3804 KB
large_ng0.txt AC 14 ms 3740 KB
large_ng1.txt AC 13 ms 3836 KB
large_ng2.txt AC 13 ms 3852 KB
sample1.txt AC 2 ms 3516 KB
sample2.txt AC 2 ms 3532 KB
small1.txt AC 2 ms 3516 KB
small2.txt AC 2 ms 3624 KB
small3.txt AC 2 ms 3624 KB
small4.txt AC 2 ms 3596 KB
small_ng2.txt AC 2 ms 3512 KB
small_ng3.txt AC 2 ms 3468 KB
small_ng4.txt AC 2 ms 3472 KB