QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#561448#1361. Ant TypingTenshiTL 4ms3640kbC++20931b2024-09-12 22:41:152024-09-12 22:41:16

Judging History

This is the latest submission verdict.

  • [2024-09-12 22:41:16]
  • Judged
  • Verdict: TL
  • Time: 4ms
  • Memory: 3640kb
  • [2024-09-12 22:41:15]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
 
inline void read(int &x){
    int s=0; x=1;
    char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

int a[10], p[10];
string s;

int cal(){
	int res=0;
	rep(i, 1, 10) p[a[i]]=i;
	int t=1;
	for(auto e: s){
		int val=e-'0';
		res+=abs(p[val]-t);
		t=p[val];
	}
	return res;
}

signed main(){
	rep(i, 1, 9) a[i]=i;
	int res=1e9;
	cin>>s;
	do{
		res=min(res, cal());
	}while(next_permutation(a+1, a+1+9));
	cout<<res+s.size()<<endl;
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 3640kb

input:

6

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Time Limit Exceeded

input:

352836512461179399826927828445163785261417666171453483576899676763764928341261962358737253818463814858565221466575498899898835568743316628247174676952381449147193191788177911797527361649543158616436321694172452689147288835568666918784929695569394655833978219612584637258492511247969998253315177569943...

output:


result: