/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 580.0 KiB
#2 Accepted 1ms 580.0 KiB
#3 Accepted 2ms 576.0 KiB
#4 Accepted 2ms 532.0 KiB
#5 Accepted 11ms 532.0 KiB
#6 Accepted 11ms 532.0 KiB
#7 Time Exceeded ≥3076ms ≥1.871 MiB
#8 Time Exceeded ≥3076ms ≥1.871 MiB
#9 Time Exceeded ≥3073ms ≥1.867 MiB
#10 Time Exceeded ≥3079ms ≥1.875 MiB
#11 Accepted 1ms 532.0 KiB
#12 Accepted 1ms 580.0 KiB
#13 Accepted 1ms 532.0 KiB
#14 Time Exceeded ≥3080ms ≥1.848 MiB

Code

#include <bits/stdc++.h> 

using namespace std;

const int mxN = 1003;
vector<vector<int>> g(mxN);
string s;
int res;

bool ispal(string t) {
  for (int i = 0, j = t.size() - 1; j > i; i++, j--) if (t[i] != t[j]) return false; return true;
}

void dfs(int node, int par, string path) {
  path += s[node];
  if (ispal(path)) res = max(res, (int)path.size()); 
  for (auto &next_node : g[node]) {
    if (next_node != par) {
      dfs(next_node, node, path);
    }
  }
  path.pop_back();
}

void solve() {
  int n, q;
  cin >> n >> s;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v, --u, --v;
    g[u].push_back(v); g[v].push_back(u);
  }
  cin >> q;
  while (q--) {
    int x; char c; cin >> x >> c;
    s[x - 1] = c;
    string t;
    res = 0;
    dfs(0, -1, t);
    cout << res << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1045 Largest palindrome in tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-11 13:41:17
Judged At
2024-10-03 13:41:59
Judged By
Score
55
Total Time
≥3080ms
Peak Memory
≥1.875 MiB