Submission #283696

#TimeUsernameProblemLanguageResultExecution timeMemory
283696arnold518Lock Puzzle (innopolis2018_final_A)C++14
78 / 100
3 ms512 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2000; int N, M; char S[MAXN+10]; char T[MAXN+10]; int cnt[30]; vector<int> V; void f(int x) { reverse(S+1, S+x+1); V.push_back(N-x); V.push_back(N-1); } int main() { scanf("%d%d", &N, &M); scanf(" %s", S+1); scanf(" %s", T+1); for(int i=1; i<=N; i++) cnt[S[i]-'a']++, cnt[T[i]-'a']--; for(int i=0; i<26; i++) if(cnt[i]!=0) return !printf("-1\n"); for(int i=N; i>=1; i--) { if(S[i]==T[i]) continue; int p; for(int j=1; j<i; j++) if(S[j]==T[i]) { p=j; break; } f(p); f(i); } printf("%d\n", V.size()); for(auto it : V) printf("%d ", it); }

Compilation message (stderr)

A.cpp: In function 'int main()':
A.cpp:41:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   41 |  printf("%d\n", V.size());
      |          ~^     ~~~~~~~~
      |           |           |
      |           int         std::vector<int>::size_type {aka long unsigned int}
      |          %ld
A.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   26 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
A.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf(" %s", S+1);
      |  ~~~~~^~~~~~~~~~~~
A.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |  scanf(" %s", T+1);
      |  ~~~~~^~~~~~~~~~~~
A.cpp:38:4: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |   f(p);
      |   ~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...